prithivMLmods/Coder-Stat huggingface dataset:
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define fi first
#define sc second
#define ALL(x) x.begin(), x.end()
#define RALL(X) x.begin(), x.end()
#define FOR(i, n, k) for (i = 0; i < n; i += k)
#define FO(i, n, k) for (i = 1; i <= n; i += k)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define N 100005
#define mid ((l + r) / 2)
#define dbg(x) (cerr << #x << " : " << x << endl)
#define endl "\n"
#define MOD 100000009

using namespace std;

typedef long long int lli;

int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> ar(n, vector<int>());
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    ar[a].pb(b);
  }

  int res = 0;
  priority_queue<int> pq;
  for (int i = m - 1; i >= 0; i--) {
    for (int x : ar[m - i])
      pq.push(x);

    if (!pq.empty()) {
      res += pq.top();
      pq.pop();
    }
  }
  cout << res;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define fi first
#define sc second
#define ALL(x) x.begin(), x.end()
#define RALL(X) x.begin(), x.end()
#define FOR(i, n, k) for (i = 0; i < n; i += k)
#define FO(i, n, k) for (i = 1; i <= n; i += k)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define N 100005
#define mid ((l + r) / 2)
#define dbg(x) (cerr << #x << " : " << x << endl)
#define endl "\n"
#define MOD 100000009

using namespace std;

typedef long long int lli;

int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> ar(100005, vector<int>());
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    ar[a].pb(b);
  }

  int res = 0;
  priority_queue<int> pq;
  for (int i = m - 1; i >= 0; i--) {
    for (int x : ar[m - i])
      pq.push(x);

    if (!pq.empty()) {
      res += pq.top();
      pq.pop();
    }
  }
  cout << res;
  return 0;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <memory>
#include <queue>
#include <set>
#include <utility>
#include <vector>

#define ll long long

using namespace std;

int main(int argc, char const *argv[]) {
  ll n, m;
  cin >> n >> m;
  vector<list<ll>> a(10005, list<ll>());
  ll maxb = 0;
  for (ll i = 0; i < n; ++i) {
    ll p, q;
    cin >> p >> q;
    a[p].emplace_back(q);
  }

  priority_queue<ll> works;
  ll res = 0;
  for (ll i = m; i >= 0; --i) {
    for (auto &b : a[m - i]) {
      works.push(b);
    }
    if (!works.empty()) {
      // cerr << "i=" << i << ": " << *f << endl;
      res += works.top();
      works.pop();
    }
    // else { cerr << "i=" << i << ": " << 0 << endl;}
  }
  cout << res << endl;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <memory>
#include <queue>
#include <set>
#include <utility>
#include <vector>

#define ll long long

using namespace std;

int main(int argc, char const *argv[]) {
  ll n, m;
  cin >> n >> m;
  vector<list<ll>> a(100005, list<ll>());
  ll maxb = 0;
  for (ll i = 0; i < n; ++i) {
    ll p, q;
    cin >> p >> q;
    a[p].emplace_back(q);
  }

  priority_queue<ll> works;
  ll res = 0;
  for (ll i = m; i >= 0; --i) {
    for (auto &b : a[m - i]) {
      works.push(b);
    }
    if (!works.empty()) {
      // cerr << "i=" << i << ": " << *f << endl;
      res += works.top();
      works.pop();
    }
    // else { cerr << "i=" << i << ": " << 0 << endl;}
  }
  cout << res << endl;
}
Problem p02948 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> v(N);
  priority_queue<int> pq;
  for (int i = 0; i < N; i++) {
    int A, B;
    cin >> A >> B;
    v[i] = make_pair(A, B);
  }
  int ans = 0;
  int j = 0;
  sort(v.begin(), v.end());
  for (int i = 1; i <= M; i++) {
    if (j < N) {
      while (v[j].first <= i) {
        pq.push(v[j].second);
        j++;
        if (j >= N)
          break;
      }
    }
    if (!pq.empty()) {
      ans += pq.top();
      pq.pop();
    }
  }
  cout << ans << endl;
}

Fixed submission:
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> v(N);
  priority_queue<int> pq;
  for (int i = 0; i < N; i++) {
    int A, B;
    cin >> A >> B;
    v[i] = make_pair(A, B);
  }
  int ans = 0;
  int j = 0;
  sort(v.begin(), v.end());
  for (int i = 1; i <= M; i++) {
    if (j < N) {
      while (v[j].first <= i) {
        pq.push(v[j].second);
        j++;
        if (j >= N)
          break;
      }
    }
    if (!pq.empty()) {
      ans += pq.top();
      pq.pop();
    }
  }
  cout << ans << endl;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize "03"
#include <bits/stdc++.h>
using namespace std;

#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif

const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;

multiset<int, greater<int>> s;
vector<int> v[N];

signed main() {
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  IOS;
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    int a, b;
    cin >> a >> b;
    v[m - a + 1].push_back(b);
  }
  int ans = 0;
  for (int i = m; i >= 1; i--) {
    for (auto j : v[i])
      s.insert(j);
    if (!s.empty()) {
      ans += *s.begin();
      s.erase(s.begin());
    }
  }
  cout << ans;
  return 0;
}

Fixed submission:
#pragma GCC optimize "03"
#include <bits/stdc++.h>
using namespace std;

#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif

const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;

multiset<int, greater<int>> s;
vector<int> v[N];

signed main() {
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  IOS;
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    int a, b;
    cin >> a >> b;
    if (m - a + 1 >= 1)
      v[m - a + 1].push_back(b);
  }
  int ans = 0;
  for (int i = m; i >= 1; i--) {
    for (auto j : v[i])
      s.insert(j);
    if (!s.empty()) {
      ans += *s.begin();
      s.erase(s.begin());
    }
  }
  cout << ans;
  return 0;
}
Problem p02948 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MAX_A = 1e5 + 1;
int N, M;

void solve() {
  cin >> N >> M;
  vector<P> jobs(N);
  for (int i = 0; i < N; ++i) {
    int a, b;
    cin >> a >> b;
    jobs[i] = P(a, b);
  }
  sort(jobs.begin(), jobs.end());
  ll ans = 0;
  priority_queue<int> q;
  int start = 0;
  for (int d = 1; d <= M; ++d) {
    for (int i = start; i < N; ++i) {
      P j = jobs[i];
      if (j.first <= d) {
        q.push(j.second);
        start++;
      }
    }
    if (!q.empty()) {
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << endl;
}

int main() {
  solve();
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MAX_A = 1e5 + 1;
int N, M;

void solve() {
  cin >> N >> M;
  vector<P> jobs(N);
  for (int i = 0; i < N; ++i) {
    int a, b;
    cin >> a >> b;
    jobs[i] = P(a, b);
  }
  sort(jobs.begin(), jobs.end());
  ll ans = 0;
  priority_queue<int> q;
  int start = 0;
  for (int d = 1; d <= M; ++d) {
    for (int i = start; i < N; ++i) {
      P j = jobs[i];
      if (j.first <= d) {
        q.push(j.second);
        start++;
      } else {
        start = i;
        break;
      }
    }
    if (!q.empty()) {
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << endl;
}

int main() {
  solve();
  return 0;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
/*******************************
Author:galaxy yr
LANG:C++
Created Time:2019/08/10 20:04:35
*******************************/
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
const int maxn = 1e5 + 10;
int n, m, _time, _end, f[maxn];
long long ans;
struct Node {
  int a, b;
  bool operator<(const Node &p) {
    if (b == p.b)
      return a < p.a;
    return b > p.b;
  }
} e[maxn];
int find(int x) { return (f[x] == x ? x : f[x] = find(f[x])); }
int main() {
  // freopen("d.in","r",stdin);
  // freopen("d.out","w",stdout);
  cin >> n >> m;
  m++;
  for (int i = 1; i <= n; i++)
    cin >> e[i].a >> e[i].b;
  sort(e + 1, e + n + 1);
  for (int i = 1; i <= m; i++)
    f[i] = i;
  for (int i = 1; i <= n; i++) {
    int fa = find(m - e[i].a);
    if (fa != 0) {
      ans += e[i].b;
      f[fa] = find(fa - 1);
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
/*******************************
Author:galaxy yr
LANG:C++
Created Time:2019/08/10 20:04:35
*******************************/
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
const int maxn = 1e5 + 10;
int n, m, _time, _end, f[maxn];
long long ans;
struct Node {
  int a, b;
  bool operator<(const Node &p) {
    if (b == p.b)
      return a < p.a;
    return b > p.b;
  }
} e[maxn];
int find(int x) { return (f[x] == x ? x : f[x] = find(f[x])); }
int main() {
  // freopen("d.in","r",stdin);
  // freopen("d.out","w",stdout);
  cin >> n >> m;
  m++;
  for (int i = 1; i <= n; i++)
    cin >> e[i].a >> e[i].b;
  sort(e + 1, e + n + 1);
  for (int i = 1; i <= m; i++)
    f[i] = i;
  for (int i = 1; i <= n; i++) {
    if (m - e[i].a < 0)
      continue;
    int fa = find(m - e[i].a);
    if (fa != 0) {
      ans += e[i].b;
      f[fa] = find(fa - 1);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> tasks(m + 1, vector<int>(0));

  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    tasks.at(a).push_back(b);
  }

  int answer = 0;

  priority_queue<int> q;

  for (int i = 1; i < m + 1; i++) {
    for (int j = 0; j < tasks.at(i).size(); j++) {
      q.push(tasks.at(i).at(j));
    }

    if (q.size() != 0) {
      answer += q.top();
      q.pop();
    }
  }

  cout << answer << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> tasks(m + 1, vector<int>(0));

  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;

    if (a < m + 1) {
      tasks.at(a).push_back(b);
    }
  }

  int answer = 0;

  priority_queue<int> q;

  for (int i = 1; i < m + 1; i++) {
    for (int j = 0; j < tasks.at(i).size(); j++) {
      q.push(tasks.at(i).at(j));
    }

    if (q.size() != 0) {
      answer += q.top();
      q.pop();
    }
  }

  cout << answer << endl;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long llu;

int main(int argc, char *argv[]) {
  ll n, m;
  cin >> n >> m;

  vector<vector<ll>> v(m + 1);
  for (ll i = 0; i < n; ++i) {
    ll a, b;
    cin >> a >> b;
    v[a].push_back(b);
  }

  priority_queue<ll> pq;
  ll ans = 0;
  for (ll i = 1; i <= m; ++i) {
    for (auto itr = v[i].begin(); itr != v[i].end(); ++itr) {
      pq.push(*itr);
    }

    if (pq.empty())
      continue;
    ans += pq.top();
    pq.pop();
  }

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long llu;

int main(int argc, char *argv[]) {
  ll n, m;
  cin >> n >> m;

  vector<vector<ll>> v(m + 1);
  for (ll i = 0; i < n; ++i) {
    ll a, b;
    cin >> a >> b;
    if (a > m)
      continue;
    v[a].push_back(b);
  }

  priority_queue<ll> pq;
  ll ans = 0;
  for (ll i = 1; i <= m; ++i) {
    for (auto itr = v[i].begin(); itr != v[i].end(); ++itr) {
      pq.push(*itr);
    }

    if (pq.empty())
      continue;
    ans += pq.top();
    pq.pop();
  }

  cout << ans << endl;

  return 0;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;
const long double EPS = 1e-10;

vector<int> job[100005];

int main() {
  int n, m;
  cin >> n >> m;

  int a, b;
  rep(i, n) {
    cin >> a >> b;
    job[a - 1].push_back(b);
  }

  priority_queue<int> pq;
  int ans = 0;
  rep(i, m) {
    for (int x : job[i])
      pq.push(x);
    ans += pq.top();
    pq.pop();
  }
  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;
const long double EPS = 1e-10;

vector<int> job[100005];

int main() {
  int n, m;
  cin >> n >> m;

  int a, b;
  rep(i, n) {
    cin >> a >> b;
    job[a - 1].push_back(b);
  }

  priority_queue<int> pq;
  int ans = 0;
  rep(i, m) {
    for (int x : job[i])
      pq.push(x);
    if (pq.empty())
      continue;
    ans += pq.top();
    pq.pop();
  }
  cout << ans << endl;

  return 0;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;

  vector<vector<int>> jobs(M); // i日目に選択出来る仕事

  rep(i, N) {
    int a, b;
    cin >> a >> b;
    jobs[M - a].push_back(b);
  }

  priority_queue<int> q;
  long ans = 0;

  for (int i = M - 1; i >= 0; i--) {
    for (int p : jobs[i]) {
      q.push(p);
    }
    if (!q.empty()) {
      ans += q.top();
      q.pop();
    }
  }

  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;

  vector<vector<int>> jobs(M); // i日目に選択出来る仕事

  rep(i, N) {
    int a, b;
    cin >> a >> b;
    if (a > M)
      continue;
    jobs[M - a].push_back(b);
  }

  priority_queue<int> q;
  long ans = 0;

  for (int i = M - 1; i >= 0; i--) {
    for (int p : jobs[i]) {
      q.push(p);
    }
    if (!q.empty()) {
      ans += q.top();
      q.pop();
    }
  }

  cout << ans << endl;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
using namespace std;
struct node {
  int x, y;
} a[100005];
bool cmp(node a, node b) { return a.y > b.y || (a.y == b.y && a.x < b.x); }
int n, m, i, ans, f[100005];
int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }
int main() {
  scanf("%d%d", &n, &m);
  m++;
  for (i = 1; i <= n; i++)
    scanf("%d%d", &a[i].x, &a[i].y);
  sort(a + 1, a + n + 1, cmp);
  for (i = 1; i <= m; i++)
    f[i] = i;
  for (i = 1; i <= n; i++)
    if (find(f[m - a[i].x]))
      ans += a[i].y, f[find(f[m - a[i].x])] = f[find(f[m - a[i].x] - 1)];
  printf("%d\n", ans);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
using namespace std;
struct node {
  int x, y;
} a[100005];
bool cmp(node a, node b) { return a.y > b.y || (a.y == b.y && a.x < b.x); }
int n, m, i, ans, f[100005];
int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }
int main() {
  scanf("%d%d", &n, &m);
  m++;
  for (i = 1; i <= n; i++)
    scanf("%d%d", &a[i].x, &a[i].y);
  sort(a + 1, a + n + 1, cmp);
  for (i = 1; i <= m; i++)
    f[i] = i;
  for (i = 1; i <= n; i++)
    if (m > a[i].x && find(f[m - a[i].x]))
      ans += a[i].y, f[find(f[m - a[i].x])] = f[find(f[m - a[i].x]) - 1];
  printf("%d\n", ans);
  return 0;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int n, m;
vector<int> vs[100000];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    if (m - a < 0)
      continue;
    vs[m - a].push_back(b);
  }

  priority_queue<int> q;
  long ans = 0;
  for (int j = m; j >= 0; --j) {
    for (int c : vs[j]) {
      q.push(c);
    }
    if (q.empty())
      continue;
    ans += q.top();
    q.pop();
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int n, m;
vector<int> vs[100001];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    if (m - a < 0)
      continue;
    vs[m - a].push_back(b);
  }

  priority_queue<int> q;
  long ans = 0;
  for (int j = m; j >= 0; --j) {
    for (int c : vs[j]) {
      q.push(c);
    }
    if (q.empty())
      continue;
    ans += q.top();
    q.pop();
  }
  cout << ans << endl;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

using ll = long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};

int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  ll a, b;
  vector<ll> jobs[10001];
  for (int i = 0; i < n; ++i) {
    cin >> a >> b;
    jobs[a].push_back(b);
  }

  priority_queue<ll> que;
  ll ans = 0;
  for (int i = m - 1; i >= 0; --i) {
    for (ll j : jobs[m - i]) {
      que.push(j);
    }
    if (!que.empty()) {
      ans += que.top();
      que.pop();
    }
  }

  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

using ll = long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};

int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  ll a, b;
  vector<ll> jobs[100001];
  for (int i = 0; i < n; ++i) {
    cin >> a >> b;
    jobs[a].push_back(b);
  }

  priority_queue<ll> que;
  ll ans = 0;
  for (int i = m - 1; i >= 0; --i) {
    for (ll j : jobs[m - i]) {
      que.push(j);
    }
    if (!que.empty()) {
      ans += que.top();
      que.pop();
    }
  }

  cout << ans << endl;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  int i, j, k;
  int a, b;
  int ans = 0;
  pair<int, int> p[M];
  priority_queue<int> q;
  for (i = 0; i < N; i++) {
    cin >> a >> b;
    p[i] = make_pair(a, b);
  }
  sort(p, p + N);
  j = 0;
  for (i = 1; i <= M; i++) {
    if (j < N) {
      while (i >= p[j].first) {
        q.push(p[j].second);
        j++;
        if (j >= N)
          break;
      }
    }
    if (!q.empty()) {
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  int i, j, k;
  int a, b;
  int ans = 0;
  pair<int, int> p[N];
  priority_queue<int> q;
  for (i = 0; i < N; i++) {
    cin >> a >> b;
    p[i] = make_pair(a, b);
  }
  sort(p, p + N);
  j = 0;
  for (i = 1; i <= M; i++) {
    if (j < N) {
      while (i >= p[j].first) {
        q.push(p[j].second);
        j++;
        if (j >= N)
          break;
      }
    }
    if (!q.empty()) {
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << endl;
}
Problem p02948 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _GLIBCXX_DEBUG // 空コンテナ操作禁止　Clang環境では#define _LIBCPP_DEBUG
                       // 0
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;

int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> p; // firstがA日後に入金、second 入金額
  int tmpA, tmpB;
  pair<int, int> tmpP;
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      arbeit;
  for (int i = 0; i < N; i++) {
    cin >> tmpA >> tmpB;
    tmpP = make_pair(tmpA, tmpB);
    arbeit.push(tmpP);
  }
  /*
    for( int i=0; i<N; i++ ){
      cout << arbeit.top().first << " " << arbeit.top().second << endl;
      arbeit.pop();
    }*/

  priority_queue<int> pq;
  int earn = 0;

  for (int day = 1; day <= M; day++) {
    //    printf( "Day %d\n", day );
    while (!arbeit.empty() && arbeit.top().first == day) {
      pq.push(arbeit.top().second);
      arbeit.pop();
    }
    if (pq.empty())
      continue;
    earn += pq.top();
    pq.pop();
  }

  cout << earn;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;

int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> p; // firstがA日後に入金、second 入金額
  int tmpA, tmpB;
  pair<int, int> tmpP;
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      arbeit;
  for (int i = 0; i < N; i++) {
    cin >> tmpA >> tmpB;
    tmpP = make_pair(tmpA, tmpB);
    arbeit.push(tmpP);
  }
  /*
    for( int i=0; i<N; i++ ){
      cout << arbeit.top().first << " " << arbeit.top().second << endl;
      arbeit.pop();
    }*/

  priority_queue<int> pq;
  int earn = 0;

  for (int day = 1; day <= M; day++) {
    //    printf( "Day %d\n", day );
    while (!arbeit.empty() && arbeit.top().first == day) {
      pq.push(arbeit.top().second);
      arbeit.pop();
    }
    if (pq.empty())
      continue;
    earn += pq.top();
    pq.pop();
  }

  cout << earn;
  return 0;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {
  int M, N;
  cin >> N >> M;

  vector<int> works[10001];

  for (int i = 0; i < N; i++) {
    int A, B;
    cin >> A >> B;
    works[A].push_back(B);
  }

  priority_queue<int> que;
  long long score = 0;
  for (int i = 1; i <= M; i++) {
    for (int j = 0; j < works[i].size(); j++) {
      que.push(works[i][j]);
    }
    if (!que.empty()) {
      score += que.top();
      que.pop();
    }
  }

  cout << score << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {
  int M, N;
  cin >> N >> M;

  vector<int> works[100001];

  for (int i = 0; i < N; i++) {
    int A, B;
    cin >> A >> B;
    works[A].push_back(B);
  }

  priority_queue<int> que;
  long long score = 0;
  for (int i = 1; i <= M; i++) {
    for (int j = 0; j < works[i].size(); j++) {
      que.push(works[i][j]);
    }
    if (!que.empty()) {
      score += que.top();
      que.pop();
    }
  }

  cout << score << endl;

  return 0;
}
Problem p02948 (Python)

Buggy submission (status: Time Limit Exceeded):
import heapq

N, M = map(int, input().split())
dic = {}
for i in range(N):
    A, B = map(int, input().split())
    if A not in dic:
        dic[A] = [-B]
    else:
        dic[A].append(-B)
# print(dic, sorted(dic.keys()))

ans = 0
heap = []

for i in range(M):
    # print(i)
    if i + 1 in dic:
        heap.extend(dic[i + 1])
    heapq.heapify(heap)
    # print(heap)
    if heap:
        ans = ans - heapq.heappop(heap)

print(ans)


Fixed submission:
import heapq

N, M = map(int, input().split())
dic = {}
for i in range(N):
    A, B = map(int, input().split())
    if A not in dic:
        dic[A] = [-B]
    else:
        dic[A].append(-B)
# print(dic, sorted(dic.keys()))

ans = 0
heap = []

for i in range(M):
    # print(i)
    if i + 1 in dic:
        for j in dic[i + 1]:
            heapq.heappush(heap, j)
    # print(heap)
    if heap:
        ans = ans - heapq.heappop(heap)

print(ans)
Problem p02948 (Python)

Buggy submission (status: Runtime Error):
import heapq

n, m = map(int, input().split())
lis = []
for i in range(n + 1):
    lis.append([])

for i in range(n):
    a, b = map(int, input().split())
    if a <= m:
        lis[a].append(-b)

cnd = []
heapq.heapify(cnd)
res = 0

for j in range(1, m + 1):
    for e in lis[j]:
        heapq.heappush(cnd, e)
    if cnd:
        res += -heapq.heappop(cnd)
print(res)


Fixed submission:
import heapq

n, m = map(int, input().split())
lis = []
for i in range(m + 1):
    lis.append([])

for i in range(n):
    a, b = map(int, input().split())
    if a <= m:
        lis[a].append(-b)

cnd = []
heapq.heapify(cnd)
res = 0

for j in range(1, m + 1):
    for e in lis[j]:
        heapq.heappush(cnd, e)
    if cnd:
        res += -heapq.heappop(cnd)
print(res)
Problem p02948 (Python)

Buggy submission (status: Runtime Error):
from heapq import heappop, heapify, heappush


def main():
    n, m = map(int, input().split())
    work = [[] for _ in range(10**4 + 1)]
    for _ in range(n):
        a, b = map(int, input().split())
        work[a].append(b)
    ans = 0
    q = []
    heapify(q)
    for i in range(1, m + 1):
        for w in work[i]:
            heappush(q, -w)
        if len(q) == 0:
            continue
        ans += heappop(q)
    ans *= -1
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
from heapq import heappop, heapify, heappush


def main():
    n, m = map(int, input().split())
    work = [[] for _ in range(10**5 + 1)]
    for _ in range(n):
        a, b = map(int, input().split())
        work[a].append(b)
    ans = 0
    q = []
    heapify(q)
    for i in range(1, m + 1):
        for w in work[i]:
            heappush(q, -w)
        if len(q) == 0:
            continue
        ans += heappop(q)
    ans *= -1
    print(ans)


if __name__ == "__main__":
    main()
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int mod = 1000000007;

void solve() {

  int n, m;
  cin >> n >> m;
  vector<vector<int>> jobs(n + 1);

  rep(i, n) {
    int a, b;
    cin >> a >> b;

    if (a > m)
      continue;

    jobs[m - a].push_back(b);
  }

  priority_queue<int> q;
  ll ans = 0;

  for (int i = m - 1; i >= 0; i--) {

    for (auto x : jobs[i]) {
      q.push(x);
    }

    if (!q.empty()) {

      int temp = q.top();
      ans += temp;
      q.pop();
    }
  }

  cout << ans;
}

int main() {

  int y;

  y = 1;
  // cin>>y ;

  while (y--) {
    solve();
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int mod = 1000000007;

void solve() {

  int n, m;
  cin >> n >> m;
  vector<vector<int>> jobs(m + 1);

  rep(i, n) {
    int a, b;
    cin >> a >> b;

    if (a > m)
      continue;

    jobs[m - a].push_back(b);
  }

  priority_queue<int> q;
  ll ans = 0;

  for (int i = m - 1; i >= 0; i--) {

    for (auto x : jobs[i]) {
      q.push(x);
    }

    if (!q.empty()) {

      int temp = q.top();
      ans += temp;
      q.pop();
    }
  }

  cout << ans;
}

int main() {

  int y;

  y = 1;
  // cin>>y ;

  while (y--) {
    solve();
  }
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a[10001];
  for (int i = 0; i < n; i++) {
    int b, c;
    cin >> b >> c;
    a[b].push_back(c);
  }
  int ans = 0;
  priority_queue<int> q;
  for (int i = 1; i <= m; i++) {
    for (int x : a[i])
      q.push(x);
    if (q.size()) {
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a[100001];
  for (int i = 0; i < n; i++) {
    int b, c;
    cin >> b >> c;
    a[b].push_back(c);
  }
  int ans = 0;
  priority_queue<int> q;
  for (int i = 1; i <= m; i++) {
    for (int x : a[i])
      q.push(x);
    if (q.size()) {
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
using namespace std;
typedef long long ll;
struct node {
  int a, b;
  bool operator<(const node &T) const {
    if (T.a == a)
      return b < T.b;
    return a < T.a;
  }
};
node a[1111] = {0};
int main() {
  ios::sync_with_stdio(false);
  cin.tie();
  int n, k, m, d;
  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    cin >> a[i].a >> a[i].b;
  }
  sort(a, a + n);
  priority_queue<int> q;
  while (!q.empty()) {
    q.pop();
  }
  long long sum = 0;
  int ind = 0;
  for (int i = 1; i <= d; i++) {
    while (ind < n && a[ind].a <= i) {
      q.push(a[ind].b);
      ind++;
    }

    if (!q.empty()) {
      // cout << q.top() << endl;
      sum += q.top();
      q.pop();
    }
  }
  cout << sum << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
using namespace std;
typedef long long ll;
struct node {
  int a, b;
  bool operator<(const node &T) const {
    if (T.a == a)
      return b < T.b;
    return a < T.a;
  }
};
node a[111100] = {0};
int main() {
  ios::sync_with_stdio(false);
  cin.tie();
  int n, k, m, d;
  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    cin >> a[i].a >> a[i].b;
  }
  sort(a, a + n);
  priority_queue<int> q;
  while (!q.empty()) {
    q.pop();
  }
  long long sum = 0;
  int ind = 0;
  for (int i = 1; i <= d; i++) {
    while (ind < n && a[ind].a <= i) {
      q.push(a[ind].b);
      ind++;
    }

    if (!q.empty()) {
      // cout << q.top() << endl;
      sum += q.top();
      q.pop();
    }
  }
  cout << sum << endl;
  return 0;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define _GLIBCXX_DEBUG
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> vec[m + 1];
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    vec[a].push_back(b);
  }
  long ans = 0;
  priority_queue<int> q;
  for (int i = 1; i < m + 1; i++) {
    if (vec[i].size() != 0) {
      for (int x : vec[i]) {
        q.push(x);
      }
    }
    if (q.size() == 0) {
      continue;
    } else {
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define _GLIBCXX_DEBUG
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> vec[100010];
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    vec[a].push_back(b);
  }
  long ans = 0;
  priority_queue<int> q;
  for (int i = 1; i < m + 1; i++) {
    if (vec[i].size() != 0) {
      for (int x : vec[i]) {
        q.push(x);
      }
    }
    if (q.size() == 0) {
      continue;
    } else {
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << endl;

  return 0;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, n) for (int i = n; i >= 0; --i)
const int inf = 1e9 + 7;
const ll mod = 1e9 + 7;
const ll big = 1e18;
const double PI = 2 * asin(1);

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> arr(M);
  int A, B;
  for (int i = 0; i < N; ++i) {
    cin >> A >> B;
    A--;
    arr[A].push_back(B);
  }
  multiset<int> st;
  auto index = st.begin();
  int ans = 0;
  for (int i = 0; i < M; ++i) {
    for (int j = 0; j < arr[i].size(); ++j)
      st.insert(arr[i][j]);
    if (st.size() == 0)
      continue;
    index = st.end();
    index--;
    ans += *index;
    st.erase(st.find(*index));
  }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, n) for (int i = n; i >= 0; --i)
const int inf = 1e9 + 7;
const ll mod = 1e9 + 7;
const ll big = 1e18;
const double PI = 2 * asin(1);

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> arr(100005);
  int A, B;
  for (int i = 0; i < N; ++i) {
    cin >> A >> B;
    A--;
    arr[A].push_back(B);
  }
  multiset<int> st;
  auto index = st.begin();
  int ans = 0;
  for (int i = 0; i < M; ++i) {
    for (int j = 0; j < arr[i].size(); ++j)
      st.insert(arr[i][j]);
    if (st.size() == 0)
      continue;
    index = st.end();
    index--;
    ans += *index;
    st.erase(st.find(*index));
  }
  cout << ans << endl;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
using llong = long long;

pair<llong, llong> a[100005];
priority_queue<llong> p_que;

int main() {
  llong n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i].first >> a[i].second;
  }

  llong ans = 0;
  int idx = 0;
  sort(a, a + n);

  for (int i = m - 1; i >= 0; i--) {
    while (a[idx].first <= (m - i)) {
      p_que.push(a[idx].second);
      idx++;
    }

    if (p_que.empty())
      continue;
    ans += p_que.top();
    p_que.pop();
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
using llong = long long;

pair<llong, llong> a[100005];
priority_queue<llong> p_que;

int main() {
  llong n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i].first >> a[i].second;
  }

  llong ans = 0;
  int idx = 0;
  sort(a, a + n);

  for (int i = m - 1; i >= 0; i--) {
    while (idx < n && a[idx].first <= (m - i)) {
      p_que.push(a[idx].second);
      idx++;
    }

    if (p_que.empty())
      continue;
    ans += p_que.top();
    p_que.pop();
  }
  cout << ans << endl;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const int nax = (int)1e5 + 7;
int n, m;
int sol;
vector<int> bs[nax];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    int a, b;
    cin >> a >> b;
    a = m - a + 1;
    bs[a].push_back(b);
  }

  priority_queue<int> q;
  for (int i = m; i >= 1; i--) {
    for (auto &b : bs[i])
      q.push(b);
    if (!q.empty()) {
      sol += q.top();
      q.pop();
    }
  }
  cout << sol << "\n";

  /// toate devin valide de atunci, iau una pe zi

  return 0;
}
/**

**/


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const int nax = (int)1e5 + 7;
int n, m;
int sol;
vector<int> bs[nax];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    int a, b;
    cin >> a >> b;
    a = m - a + 1;
    if (a >= 0)
      bs[a].push_back(b);
  }

  priority_queue<int> q;
  for (int i = m; i >= 1; i--) {
    for (auto &b : bs[i])
      q.push(b);
    if (!q.empty()) {
      sol += q.top();
      q.pop();
    }
  }
  cout << sol << "\n";

  /// toate devin valide de atunci, iau una pe zi

  return 0;
}
/**

**/
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  vector<vector<int>> AB(M);
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    AB[a].emplace_back(b);
  }
  priority_queue<int> que;
  int res = 0;
  for (int i = 0; i < M; i++) {
    for (int x : AB[i]) {
      que.push(x);
    }
    if (que.empty())
      continue;
    res += que.top();
    que.pop();
  }
  cout << res << '\n';
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  vector<vector<int>> AB(M);
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    if (a > M)
      continue;
    a--;
    AB[a].emplace_back(b);
  }
  priority_queue<int> que;
  int res = 0;
  for (int i = 0; i < M; i++) {
    for (int x : AB[i]) {
      que.push(x);
    }
    if (que.empty())
      continue;
    res += que.top();
    que.pop();
  }
  cout << res << '\n';
  return 0;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

using int64 = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n, m;
  cin >> n >> m;
  vector<vector<int>> d_to_v(m + 1);
  for (int i = 0; i < n; i++) {
    int d, v;
    cin >> d >> v;
    d_to_v[d].push_back(v);
  }

  priority_queue<int> pq;
  int ans = 0;
  for (int d = 1; d <= m; d++) {
    for (int v : d_to_v[d]) {
      pq.push(v);
    }
    if (!pq.empty()) {
      ans += pq.top();
      pq.pop();
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

using int64 = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n, m;
  cin >> n >> m;
  vector<vector<int>> d_to_v(m + 1);
  for (int i = 0; i < n; i++) {
    int d, v;
    cin >> d >> v;
    if (d > m)
      continue;
    d_to_v[d].push_back(v);
  }

  priority_queue<int> pq;
  int ans = 0;
  for (int d = 1; d <= m; d++) {
    for (int v : d_to_v[d]) {
      pq.push(v);
    }
    if (!pq.empty()) {
      ans += pq.top();
      pq.pop();
    }
  }
  cout << ans << endl;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef pair<int, int> ii;
typedef long long ll;
typedef pair<ll, ll> p;
typedef unsigned long long int ull;
const ll MOD = 998244353;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
const int MAXN = 100000;
const int MAXE = 100000;
const int MAXV = 10000;
const ll INF = 2e18;

int main() {
  int n, m;
  cin >> n >> m;
  vector<ii> c(n);
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    c[i] = ii(a, b);
  }
  sort(c.begin(), c.end());
  int i = 0;
  int ans = 0;
  priority_queue<int> que;
  for (int d = 1; d <= m; d++) {
    while (c[i].first <= d && i < n) {
      que.push(c[i].second);
      i++;
    }
    int mx = que.top();
    que.pop();
    ans += mx;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef pair<int, int> ii;
typedef long long ll;
typedef pair<ll, ll> p;
typedef unsigned long long int ull;
const ll MOD = 998244353;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
const int MAXN = 100000;
const int MAXE = 100000;
const int MAXV = 10000;
const ll INF = 2e18;

int main() {
  int n, m;
  cin >> n >> m;
  vector<ii> c(n);
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    c[i] = ii(a, b);
  }
  sort(c.begin(), c.end());
  int i = 0;
  int ans = 0;
  priority_queue<int> que;
  for (int d = 1; d <= m; d++) {
    while (c[i].first <= d && i < n) {
      que.push(c[i].second);
      i++;
    }
    if (que.empty())
      continue;
    int mx = que.top();
    que.pop();
    ans += mx;
  }
  cout << ans << endl;
  return 0;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); ++i)

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> jobs(m);
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    if (a > m)
      continue;
    jobs[m - a].push_back(b);
  }
  priority_queue<int> q;
  ll ans = 0;
  for (int i = m - 1; i >= 0; ++i) {
    for (int b : jobs[i]) {
      q.push(b);
    }
    if (!q.empty()) {
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); ++i)

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> jobs(m);
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    if (a > m)
      continue;
    jobs[m - a].push_back(b);
  }
  priority_queue<int> q;
  ll ans = 0;
  for (int i = m - 1; i >= 0; --i) {
    for (int b : jobs[i]) {
      q.push(b);
    }
    if (!q.empty()) {
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << endl;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define rrep(i, a, b) for (int i = (a); i >= (b); --i)
#define MP make_pair
#define PB push_back
typedef long long LL;
const LL P = 998244353;
const int N = 1e5 + 10;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

struct dat {
  int a, b;
} a[N];
int n, m, fa[N];

int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }

int main() {
  scanf("%d%d", &n, &m);
  rep(i, 1, n) scanf("%d%d", &a[i].a, &a[i].b);
  sort(a + 1, a + n + 1, [](dat a, dat b) { return a.b > b.b; });
  rep(i, 1, m) fa[i] = i;
  LL ans = 0;
  rep(i, 1, n) {
    int j = find(m - a[i].a + 1);
    if (j <= 0)
      continue;
    ans += 1ll * a[i].b;
    fa[j] = j - 1;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define rrep(i, a, b) for (int i = (a); i >= (b); --i)
#define MP make_pair
#define PB push_back
typedef long long LL;
const LL P = 998244353;
const int N = 1e5 + 10;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

struct dat {
  int a, b;
} a[N];
int n, m, fa[N];

int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }

int main() {
  scanf("%d%d", &n, &m);
  rep(i, 1, n) scanf("%d%d", &a[i].a, &a[i].b);
  sort(a + 1, a + n + 1, [](dat a, dat b) { return a.b > b.b; });
  rep(i, 1, m) fa[i] = i;
  LL ans = 0;
  rep(i, 1, n) {
    if (m - a[i].a + 1 <= 0)
      continue;
    int j = find(m - a[i].a + 1);
    if (j <= 0)
      continue;
    ans += 1ll * a[i].b;
    fa[j] = j - 1;
  }
  cout << ans << endl;
  return 0;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define endl "\n"
#define pb push_back
#define PI 3.1415926535897932384626433832795l
#define F first
#define S second
#define mp make_pair
#define f(i, n) for (int i = 0; i < n; ++i)
#define loop(i, a, b) for (int i = a; i < b; ++i)
#define fastio                                                                 \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define gcd(a, b) __gcd((a), (b))
#define fill(a, value) memset(a, value, sizeof(a));
#define minn(v) *min_element(v.begin(), v.end());
#define maxx(v) *max_element(v.begin(), v.end());
#define print(x) cout << (x) << endl;
#define sum(v) +x accumulate(v.begin(), v.end(), x);
typedef pair<int, int> pii;
typedef vector<int> vi;

signed main() {
  fastio;
  cout << fixed << setprecision(12);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> a(n + 1);
  f(i, n) {
    int x, y;
    cin >> x >> y;
    a[x].pb(y);
  }
  multiset<int> s;
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    for (auto p : a[i]) {
      s.insert(p);
    }
    if (s.size()) {
      ans += *s.rbegin();
      s.erase(--s.end());
    }
  }
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define endl "\n"
#define pb push_back
#define PI 3.1415926535897932384626433832795l
#define F first
#define S second
#define mp make_pair
#define f(i, n) for (int i = 0; i < n; ++i)
#define loop(i, a, b) for (int i = a; i < b; ++i)
#define fastio                                                                 \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define gcd(a, b) __gcd((a), (b))
#define fill(a, value) memset(a, value, sizeof(a));
#define minn(v) *min_element(v.begin(), v.end());
#define maxx(v) *max_element(v.begin(), v.end());
#define print(x) cout << (x) << endl;
#define sum(v) +x accumulate(v.begin(), v.end(), x);
typedef pair<int, int> pii;
typedef vector<int> vi;

signed main() {
  fastio;
  cout << fixed << setprecision(12);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> a(100005);
  f(i, n) {
    int x, y;
    cin >> x >> y;
    a[x].pb(y);
  }
  multiset<int> s;
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    for (auto p : a[i]) {
      s.insert(p);
    }
    if (s.size()) {
      ans += *s.rbegin();
      s.erase(--s.end());
    }
  }
  cout << ans << endl;

  return 0;
}