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

Buggy submission (status: Runtime Error):
/*by freesteed*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define pb push_back
#define fill(x, c) memset(x, c, sizeof(x))
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(), (x).end()
#define caset                                                                  \
  int ___T;                                                                    \
  cin >> ___T;                                                                 \
  for (int cs = 1; cs <= ___T; cs++)
#define get_be(c, x) (lower_bound(c.begin(), c.end(), x) - c.begin())
// get_be biger & equal
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
const ll mod = 1e9 + 7;
const ll oo = 1e9 + 10;
const int Max = 1e6 + 10;
ll powmod(ll a, ll b) {
  ll res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}

void solve() {
  ll n, m, ans = 0;
  cin >> n >> m;
  priority_queue<int> q;
  vector<VI> job(m); // 第i天做job刚好到第m天拿工资
  rep(i, 0, n) {
    int x, y;
    cin >> x >> y;
    if (x <= m) {
      job[m - x].pb(y);
    }
  }
  for (int i = m - 1; i >= 0; i--) {
    for (int j = 0; j < job[i].size(); j++)
      q.push(job[i][j]);
    ans += q.top();
    q.pop();
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  // caset{
  solve();
  //}
  return 0;
}


Fixed submission:
/*by freesteed*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define pb push_back
#define fill(x, c) memset(x, c, sizeof(x))
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(), (x).end()
#define caset                                                                  \
  int ___T;                                                                    \
  cin >> ___T;                                                                 \
  for (int cs = 1; cs <= ___T; cs++)
#define get_be(c, x) (lower_bound(c.begin(), c.end(), x) - c.begin())
// get_be biger & equal
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
const ll mod = 1e9 + 7;
const ll oo = 1e9 + 10;
const int Max = 1e6 + 10;
ll powmod(ll a, ll b) {
  ll res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}

void solve() {
  ll n, m, ans = 0;
  cin >> n >> m;
  priority_queue<int> q;
  vector<VI> job(m); // 第i天做job刚好到第m天拿工资
  rep(i, 0, n) {
    int x, y;
    cin >> x >> y;
    if (x <= m) {
      job[m - x].pb(y);
    }
  }
  for (int i = m - 1; i >= 0; i--) {
    for (int j = 0; j < job[i].size(); j++)
      q.push(job[i][j]);
    if (!q.empty()) {
      ans += q.top();
      q.pop();
    }
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  // caset{
  solve();
  //}
  return 0;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T> void cout_vec(const vector<T> &vec) {
  for (auto itr : vec)
    cout << itr << ' ';
  cout << '\n';
}

typedef pair<ll, ll> P;
const ll mod = 1e9 + 7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  priority_queue<ll> a;
  vector<vector<ll>> now(m + 10);
  rep(i, n) {
    ll x, y;
    cin >> x >> y;
    now[x].push_back(y);
  }
  ll ans = 0;
  for (ll i = 1; i <= m; i++) {
    for (auto itr : now[i])
      a.push(itr);
    if (!a.empty()) {
      ans += a.top();
      a.pop();
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T> void cout_vec(const vector<T> &vec) {
  for (auto itr : vec)
    cout << itr << ' ';
  cout << '\n';
}

typedef pair<ll, ll> P;
const ll mod = 1e9 + 7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  priority_queue<ll> a;
  vector<vector<ll>> now(m + 10);
  rep(i, n) {
    ll x, y;
    cin >> x >> y;
    if (x > m)
      continue;
    now[x].push_back(y);
  }
  ll ans = 0;
  for (ll i = 1; i <= m; i++) {
    for (auto itr : now[i])
      a.push(itr);
    if (!a.empty()) {
      ans += a.top();
      a.pop();
    }
  }
  cout << ans << endl;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define REP(i, m, n) for (int i = (m); i < (n); i++)
#define rep(i, n) REP(i, 0, n)
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf = 1e9 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> vv(m + 1);
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    vv[a].push_back(b);
  }
  priority_queue<int> pq;
  ll ans = 0;
  rep(i, m) {
    rep(j, vv[i + 1].size()) pq.push(vv[i + 1][j]);
    if (!pq.empty()) {
      ans += pq.top();
      pq.pop();
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, m, n) for (int i = (m); i < (n); i++)
#define rep(i, n) REP(i, 0, n)
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf = 1e9 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> vv(m + 1);
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    if (a <= m)
      vv[a].push_back(b);
  }
  priority_queue<int> pq;
  ll ans = 0;
  rep(i, m) {
    rep(j, vv[i + 1].size()) pq.push(vv[i + 1][j]);
    if (!pq.empty()) {
      ans += pq.top();
      pq.pop();
    }
  }
  cout << ans << endl;
}
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;

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>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

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>
#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;
#define ll long long int
priority_queue<int> q;
vector<int> v[10001];

int main() {
  ll N, M;
  ll a, b;
  cin >> N >> M;
  rep(i, N) {
    cin >> a >> b;
    v[a].push_back(b);
  }
  ll res = 0;
  for (int i = M; i >= 1; i--) {
    for (int c : v[M - i + 1]) {
      q.push(c);
    }

    if (!q.empty()) {
      int x = q.top();
      q.pop();
      res += x;
    }
  }
  cout << res << endl;
}

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

using namespace std;
#define ll long long int
priority_queue<int> q;
vector<int> v[1000005];

int main() {
  ll N, M;
  ll a, b;
  cin >> N >> M;
  rep(i, N) {
    cin >> a >> b;
    v[a].push_back(b);
  }
  ll res = 0;
  for (int i = M; i >= 1; i--) {
    for (int c : v[M - i + 1]) {
      q.push(c);
    }

    if (!q.empty()) {
      int x = q.top();
      q.pop();
      res += x;
    }
  }
  cout << res << endl;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <queue>

using namespace std;

int n;
int m;

priority_queue<int> que;
vector<int> t[100005];

int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1, c, v; i <= n; ++i) {
    cin >> c >> v;
    t[m - c + 1].push_back(v);
  }

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

  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <iostream>
#include <queue>

using namespace std;

int n;
int m;

priority_queue<int> que;
vector<int> t[100005];

int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1, c, v; i <= n; ++i) {
    cin >> c >> v;
    if (m - c + 1 >= 1) {
      t[m - c + 1].push_back(v);
    }
  }

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

  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>> vvi(m + 1);
  int a, b;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    vvi[a].push_back(b);
  }

  int w = 0;
  priority_queue<int> pq;
  for (int i = 1; i <= m; i++) {
    for (int x : vvi[i]) {
      pq.push(x);
    }
    if (pq.empty())
      continue;
    w += pq.top();
    pq.pop();
  }

  cout << w << endl;
}

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

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

  int w = 0;
  priority_queue<int> pq;
  for (int i = 1; i <= m; i++) {
    for (int x : vvi[i]) {
      pq.push(x);
    }
    if (pq.empty())
      continue;
    w += pq.top();
    pq.pop();
  }

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template <class T> inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
typedef long long ll;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, M;
  cin >> N >> M;
  vector<vector<ll>> B(M + 1, vector<ll>());
  REP(i, N) {
    ll a, b;
    cin >> a >> b;
    if (a > M)
      continue;
    B[a].push_back(b);
  }
  priority_queue<ll> pq;
  ll ans = 0;
  for (ll i = 1; i <= M; i++) {
    if (!B[i].empty()) {
      for (auto j : B[i]) {
        pq.push(j);
      }
    }
    ans += pq.top();
    pq.pop();
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template <class T> inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
typedef long long ll;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, M;
  cin >> N >> M;
  vector<vector<ll>> B(M + 1, vector<ll>());
  REP(i, N) {
    ll a, b;
    cin >> a >> b;
    if (a > M)
      continue;
    B[a].push_back(b);
  }
  priority_queue<ll> pq;
  ll ans = 0;
  for (ll i = 1; i <= M; i++) {
    if (!B[i].empty()) {
      for (auto j : B[i]) {
        pq.push(j);
      }
    }
    if (!pq.empty()) {
      ans += pq.top();
      pq.pop();
    }
  }
  cout << ans << endl;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
bool compare(pair<int, int> a, pair<int, int> b) {
  if (a.first == b.first)
    return a.second < b.second;
  else
    return a.first < b.first;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i].first >> a[i].second;
  }
  sort(a.begin(), a.end(), compare);
  int count = 1;
  priority_queue<int> que;
  for (int i = 0; i < n; i++) {
    que.push(0);
  }
  int sum = 0;
  int buf = 0;
  for (int i = 1; i <= m; i++) {
    for (int j = buf; a[j].first <= i; j++) {
      que.push(a[j].second);
      buf++;
    }
    sum += que.top();
    que.pop();
  }
  cout << sum << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
bool compare(pair<int, int> a, pair<int, int> b) {
  if (a.first == b.first)
    return a.second < b.second;
  else
    return a.first < b.first;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i].first >> a[i].second;
  }
  sort(a.begin(), a.end(), compare);
  int count = 1;
  priority_queue<int> que;
  for (int i = 0; i < m; i++) {
    que.push(0);
  }
  int sum = 0;
  int buf = 0;
  for (int i = 1; i <= m; i++) {
    for (int j = buf; a[j].first <= i; j++) {
      que.push(a[j].second);
      buf++;
    }
    sum += que.top();
    que.pop();
  }
  cout << sum << endl;
  return 0;
}
Problem p02948 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
const ll mod = 1e9 + 7;
const int inf = 1 << 30;

vector<vector<int>> vec;

int main() {
  int n, m;
  cin >> n >> m;
  vec.resize(100010);
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    vec[a].push_back(b);
  }
  priority_queue<int> que;
  ll ans = 0;
  for (int i = 1; i <= m; i++) {
    rep(j, vec[i].size()) que.push(vec[i][j]);
    if (que.size()) {
      ans += que.top();
      que.pop();
    }
  }
  cout << ans << endl;
}

Fixed submission:
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
const ll mod = 1e9 + 7;
const int inf = 1 << 30;

vector<vector<int>> vec;

int main() {
  int n, m;
  cin >> n >> m;
  vec.resize(100010);
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    vec[a].push_back(b);
  }
  priority_queue<int> que;
  ll ans = 0;
  for (int i = 1; i <= m; i++) {
    rep(j, vec[i].size()) que.push(vec[i][j]);
    if (que.size()) {
      ans += que.top();
      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 pair<int, int> ipair;
#define pb push_back
#define MP make_pair
#define ff first
#define ss second
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(x) ((x) < 0 ? -(x) : (x))

ll mod = 1000000007;

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n, m;
  cin >> n >> m;
  vector<ipair> rec(n);
  for (int i = 0; i < n; i++) {
    cin >> rec[i].first >> rec[i].second;
  }
  sort(rec.begin(), rec.end());
  priority_queue<ipair, vector<ipair>> pq;
  int p = 0;
  ll re = 0;
  for (int i = m; i > 0; i--) {
    while (p < n && ((rec[p].first + i - 1) <= m)) {
      pq.push(make_pair(rec[p].second, rec[p].first));
      p++;
    }
    // cout<<p<<endl;
    if (!pq.empty()) {
      ipair temp = pq.top();
      pq.pop();
      // cout<<temp.first<<" "<<i<<endl;
      re += temp.first;
    }
  }
  cout << re << endl;
  return 0;
}

//-------------------------//

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

typedef long long ll;

typedef pair<int, int> ipair;
#define pb push_back
#define MP make_pair
#define ff first
#define ss second
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(x) ((x) < 0 ? -(x) : (x))

ll mod = 1000000007;

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);

  int n, m;
  cin >> n >> m;
  vector<ipair> rec(n);
  for (int i = 0; i < n; i++) {
    cin >> rec[i].first >> rec[i].second;
  }
  sort(rec.begin(), rec.end());
  priority_queue<ipair, vector<ipair>> pq;
  int p = 0;
  ll re = 0;
  for (int i = m; i > 0; i--) {
    while (p < n && ((rec[p].first + i - 1) <= m)) {
      pq.push(make_pair(rec[p].second, rec[p].first));
      p++;
    }
    // cout<<p<<endl;
    if (!pq.empty()) {
      ipair temp = pq.top();
      pq.pop();
      // cout<<temp.first<<" "<<i<<endl;
      re += temp.first;
    }
  }
  cout << re << endl;
  return 0;
}

//-------------------------//
Problem p02948 (C++)

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

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

  long N, M;
  cin >> N >> M;

  vector<vector<long>> v(M + 2);
  priority_queue<long> q;

  long A;
  int B;
  for (long i = 0; i < N; i++) {
    cin >> A >> B;

    v[A].push_back(B);
  }

  long long t = 0;
  pair<int, long> tp;
  for (long D = 1; D < M + 1; D++) {
    for (auto &vv : v[D])
      q.push(vv);

    if (q.size() > 0) {
      t += q.top();
      q.pop();
    }
  }

  cout << t << endl;

  return 0;
}

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

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

  long N, M;
  cin >> N >> M;

  vector<vector<long>> v(100010);
  priority_queue<long> q;

  long A;
  int B;
  for (long i = 0; i < N; i++) {
    cin >> A >> B;

    v[A].push_back(B);
  }

  long long t = 0;
  pair<int, long> tp;
  for (long D = 1; D < M + 1; D++) {
    for (auto &vv : v[D])
      q.push(vv);

    if (q.size() > 0) {
      t += q.top();
      q.pop();
    }
  }

  cout << t << 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 PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

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

  priority_queue<int> p;
  ll ans = 0;

  for (int i = m - 1; i >= 0; i--) {
    rep(j, job[i].size()) p.push(job[i][j]);
    if (!p.empty()) {
      ans += p.top();
      p.pop();
    }
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> job(m);
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    if (a > m)
      continue;
    job[m - a].push_back(b);
  }

  priority_queue<int> p;
  ll ans = 0;

  for (int i = m - 1; i >= 0; i--) {
    rep(j, job[i].size()) p.push(job[i][j]);
    if (!p.empty()) {
      ans += p.top();
      p.pop();
    }
  }

  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>> W(M);
  for (int i = 0; i < N; i++) {
    int A, B;
    cin >> A >> B;
    W[M - A].push_back(B);
  }
  int ans = 0;
  priority_queue<int> pq;
  for (int i = M - 1; i >= 0; i--) {
    for (int j : W[i]) {
      pq.push(j);
    }
    if (!pq.empty()) {
      ans += pq.top();
      pq.pop();
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> W(M);
  for (int i = 0; i < N; i++) {
    int A, B;
    cin >> A >> B;
    if (M - A >= 0) {
      W[M - A].push_back(B);
    }
  }
  int ans = 0;
  priority_queue<int> pq;
  for (int i = M - 1; i >= 0; i--) {
    for (int j : W[i]) {
      pq.push(j);
    }
    if (!pq.empty()) {
      ans += pq.top();
      pq.pop();
    }
  }
  cout << ans << endl;
}
Problem p02948 (C++)

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

#define int long long

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N, M;
  cin >> N >> M;

  using P = pair<int, int>;
  priority_queue<P> Q;
  vector<int> v[100000];
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    // Q.push(P(b, a));
    v[a].push_back(b);
  }

  int ans = 0;
  for (int i = 1; i <= M; i++) {
    for (int j : v[i]) {
      Q.push(P(j, i));
    }
    if (Q.size()) {
      int j = Q.top().first;
      Q.pop();
      ans += j;
    }
  }

  cout << ans << endl;

  return 0;
}


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

#define int long long

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N, M;
  cin >> N >> M;

  using P = pair<int, int>;
  priority_queue<P> Q;
  vector<int> v[100010];
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    // Q.push(P(b, a));
    v[a].push_back(b);
  }

  int ans = 0;
  for (int i = 1; i <= M; i++) {
    for (int j : v[i]) {
      Q.push(P(j, i));
    }
    if (Q.size()) {
      int j = Q.top().first;
      Q.pop();
      ans += j;
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int M = 100005;
int n, m;
struct node {
  int yc, val;
} A[M];
bool comp(node a, node b) { return a.val > b.val; }
bool mark[M];
set<int> s;
set<int>::iterator it;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    scanf("%d%d", &A[i].yc, &A[i].val);
  sort(A + 1, A + n + 1, comp);
  int ans = 0;
  for (int i = 0; i <= m; i++)
    s.insert(-i);
  for (int i = 1; i <= n; i++) {
    int t = m - A[i].yc;
    if (t < 0)
      continue;
    it = s.lower_bound(-t);
    if (it == s.end())
      continue;
    int k = -(*it);
    mark[-k] = 1;
    s.erase(-k);
    ans += A[i].val;
  }
  printf("%d\n", ans);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int M = 100005;
int n, m;
struct node {
  int yc, val;
} A[M];
bool comp(node a, node b) { return a.val > b.val; }
bool mark[M];
set<int> s;
set<int>::iterator it;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    scanf("%d%d", &A[i].yc, &A[i].val);
  sort(A + 1, A + n + 1, comp);
  int ans = 0;
  for (int i = 0; i <= m; i++)
    s.insert(-i);
  for (int i = 1; i <= n; i++) {
    int t = m - A[i].yc;
    if (t < 0)
      continue;
    it = s.lower_bound(-t);
    if (it == s.end())
      continue;
    int k = -(*it);
    mark[k] = 1;
    s.erase(-k);
    ans += A[i].val;
  }
  printf("%d\n", ans);
}
Problem p02948 (C++)

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

typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define MP make_pair // pairのコンストラクタ
#define F first      // pairの一つ目の要素
#define S second     // pairの二つ目の要素
#define dump(x) cout << #x << " = " << (x) << endl; // debug
#define SZ(x) ((ll)(x).size())
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << (v) << endl;
#define ALL(a) (a).begin(), (a).end()
#define RANGE(a, start_index, num)                                             \
  (a).begin() + (start_index), (a).begin() + (num)

int main() {
  vector<pair<int, int>> ab;
  int n, m;
  cin >> n >> m;
  FOR(i, 1, n) {
    int a, b;
    cin >> a >> b;
    ab.push_back(MP(a, b));
  }
  sort(ALL(ab));
  priority_queue<int> pq;

  int starti = 0;
  int now = 1;
  ll res = 0;
  while (1) {
    FOR(i, starti, n - 1) {
      if (ab[i].F == now) {
        pq.push(ab[i].S);
        starti = i + 1;
      }
    }
    if (!pq.empty()) {
      res += pq.top();
      pq.pop();
    }
    now++;
    if (now == m + 1)
      break;
  }
  pv(res);
}

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

typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define MP make_pair // pairのコンストラクタ
#define F first      // pairの一つ目の要素
#define S second     // pairの二つ目の要素
#define dump(x) cout << #x << " = " << (x) << endl; // debug
#define SZ(x) ((ll)(x).size())
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << (v) << endl;
#define ALL(a) (a).begin(), (a).end()
#define RANGE(a, start_index, num)                                             \
  (a).begin() + (start_index), (a).begin() + (num)

int main() {
  vector<pair<int, int>> ab;
  int n, m;
  cin >> n >> m;
  FOR(i, 1, n) {
    int a, b;
    cin >> a >> b;
    ab.push_back(MP(a, b));
  }
  sort(ALL(ab));
  priority_queue<int> pq;

  int starti = 0;
  int now = 1;
  ll res = 0;
  while (1) {
    FOR(i, starti, n - 1) {
      if (ab[i].F == now) {
        pq.push(ab[i].S);
      } else {
        starti = i;
        break;
      }
    }
    if (!pq.empty()) {
      res += pq.top();
      pq.pop();
    }
    now++;
    if (now == m + 1)
      break;
  }
  pv(res);
}
Problem p02948 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> jobs(m);

  // 二次元配列に詰め込む
  for (int i = 0; i < n; i++) {
    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--) {
    // pythonでいうfor i in hoge みたいなimage
    for (int b : jobs[i]) {
      q.push(b);
    }

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

Fixed submission:
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> jobs(m);

  // 二次元配列に詰め込む
  for (int i = 0; i < n; i++) {
    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--) {
    // pythonでいうfor i in hoge みたいなimage
    for (int j = 0; j < jobs[i].size(); j++) {
      int b = jobs[i][j];
      q.push(b);
    }

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, N) for (ll i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

//++時計回り --反時計回り
// int dx[4] = {1, 0, -1, 0};
// int dy[4] = {0, 1, 0, -1};

int main() {
  ll N, M;
  cin >> N >> M;
  vector<vector<ll>> v(M + 1);
  REP(i, N) {
    ll a, b;
    cin >> a >> b;
    v[a].PB(b);
  }
  ll ans = 0;
  priority_queue<ll> pq;
  for (ll i = 1; i <= M; i++) {
    for (auto e : v[i])
      pq.push(e);
    if (pq.size() != 0) {
      ans += pq.top();
      pq.pop();
    }
  }
  cout << ans << '\n';
}


Fixed submission:
#include <bits/stdc++.h>
#define REP(i, N) for (ll i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

//++時計回り --反時計回り
// int dx[4] = {1, 0, -1, 0};
// int dy[4] = {0, 1, 0, -1};

int main() {
  ll N, M;
  cin >> N >> M;
  vector<vector<ll>> v(1e5 + 1);
  REP(i, N) {
    ll a, b;
    cin >> a >> b;
    v[a].PB(b);
  }
  ll ans = 0;
  priority_queue<ll> pq;
  for (ll i = 1; i <= M; i++) {
    for (auto e : v[i])
      pq.push(e);
    if (pq.size() != 0) {
      ans += pq.top();
      pq.pop();
    }
  }
  cout << ans << '\n';
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;
int main() {
  int n, m, a, b, ans = 0;
  cin >> n >> m;
  priority_queue<int> que;
  vector<int> v[100000];
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    v[a].push_back(b);
  }
  for (int i = 1; i <= m; i++) {
    for (auto p : v[i]) {
      que.push(p);
    }
    if (que.size()) {
      ans += que.top();
      que.pop();
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;
int main() {
  int n, m, a, b, ans = 0;
  cin >> n >> m;
  priority_queue<int> que;
  vector<int> v[100005];
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    v[a].push_back(b);
  }
  for (int i = 1; i <= m; i++) {
    for (auto p : v[i]) {
      que.push(p);
    }
    if (que.size()) {
      ans += que.top();
      que.pop();
    }
  }
  cout << ans << endl;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <queue>
#include <utility>
using namespace std;
int n, m, a, b;
pair<int, int> p[100000];
priority_queue<int> que;
int ans;
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    cin >> a >> b, p[i] = make_pair(a, b);
  sort(p, p + n);
  int x = 0;
  for (int i = 1; i <= m; i++) {
    for (; p[x].first <= i; x++)
      que.push(p[x].second);
    if (!que.empty())
      ans += que.top(), que.pop();
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <queue>
#include <utility>
using namespace std;
int n, m, a, b;
pair<int, int> p[100000];
priority_queue<int> que;
int ans;
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    cin >> a >> b, p[i] = make_pair(a, b);
  sort(p, p + n);
  int x = 0;
  for (int i = 1; i <= m; i++) {
    for (; x < n && p[x].first <= i; x++)
      que.push(p[x].second);
    if (!que.empty())
      ans += que.top(), que.pop();
  }
  cout << ans << endl;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long
const int maxn = (int)1e6 + 6;
using namespace std;
signed main() {
  priority_queue<int> pq;
  int n, m, sum = 0;
  cin >> n >> m;
  vector<int> vec[n];
  for (int i = 0; i < n; i++) {
    int days, score;
    cin >> days >> score;
    vec[days].push_back(score);
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 0; j < (int)vec[i].size(); j++) {
      pq.push(vec[i][j]);
    }
    if (!pq.empty()) {
      sum += pq.top();
      pq.pop();
    }
  }
  cout << sum;
}

Fixed submission:
#include <bits/stdc++.h>
#define int long long
const int maxn = (int)1e6 + 6;
using namespace std;
signed main() {
  priority_queue<int> pq;
  int n, m, sum = 0;
  cin >> n >> m;
  vector<int> vec[maxn];
  for (int i = 0; i < n; i++) {
    int days, score;
    cin >> days >> score;
    vec[days].push_back(score);
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 0; j < (int)vec[i].size(); j++) {
      pq.push(vec[i][j]);
    }
    if (!pq.empty()) {
      sum += pq.top();
      pq.pop();
    }
  }
  cout << sum;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

typedef long long ll;

int main() {
  int N, M;
  std::cin >> N >> M;
  int A, B;
  std::vector<std::vector<int>> AB(M);
  for (int i = 0; i < N; ++i) {
    std::cin >> A >> B;
    AB[M - A].push_back(B);
  }

  ll ans = 0;
  std::priority_queue<int> que;
  for (int i = M - 1; i >= 0; --i) {
    for (int b : AB[i])
      que.push(b);
    if (!que.empty()) {
      ans += que.top();
      que.pop();
    }
  }
  std::cout << ans << std::endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

typedef long long ll;

int main() {
  int N, M;
  std::cin >> N >> M;
  int A, B;
  std::vector<std::vector<int>> AB(M);
  for (int i = 0; i < N; ++i) {
    std::cin >> A >> B;
    if (A > M)
      continue;
    AB[M - A].push_back(B);
  }

  ll ans = 0;
  std::priority_queue<int> que;
  for (int i = M - 1; i >= 0; --i) {
    for (int b : AB[i])
      que.push(b);
    if (!que.empty()) {
      ans += que.top();
      que.pop();
    }
  }
  std::cout << ans << std::endl;
  return 0;
}
Problem p02948 (C++)

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

int main() {
  int n, m, x, y, p = 0, i, k, j;
  cin >> n >> m;
  vector<int> v[m];
  for (i = 0; i < n; i++) {
    cin >> x >> y;
    if (x <= m) {
      v[x].push_back(y);
    }
  }
  priority_queue<int> pq;

  for (i = 1; i <= m; i++) {
    for (j = 0; j < v[i].size(); j++) {
      k = v[i][j];
      pq.push(k);
    }
    if (!pq.empty()) {
      p = p + pq.top();
      pq.pop();
    }
  }
  cout << p << endl;
  return 0;
}


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

int main() {
  int n, m, x, y, p = 0, i, k, j;
  cin >> n >> m;
  vector<int> v[m + 1];
  for (i = 0; i < n; i++) {
    cin >> x >> y;
    if (x <= m) {
      v[x].push_back(y);
    }
  }
  priority_queue<int> pq;

  for (i = 1; i <= m; i++) {
    for (j = 0; j < v[i].size(); j++) {
      k = v[i][j];
      pq.push(k);
    }
    if (!pq.empty()) {
      p = p + pq.top();
      pq.pop();
    }
  }
  cout << p << endl;
  return 0;
}
Problem p02948 (C++)

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

int main() {
  int n, m, x, y, p = 0, i, k, j;
  cin >> n >> m;
  vector<int> v[n + 1];
  for (i = 0; i < n; i++) {
    cin >> x >> y;
    if (x <= m) {
      v[x].push_back(y);
    }
  }
  priority_queue<int> pq;

  for (i = 1; i <= m; i++) {
    for (j = 0; j < v[i].size(); j++) {
      k = v[i][j];
      pq.push(k);
    }
    if (!pq.empty()) {
      p = p + pq.top();
      pq.pop();
    }
  }
  cout << p << endl;
  return 0;
}


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

int main() {
  int n, m, x, y, p = 0, i, k, j;
  cin >> n >> m;
  vector<int> v[m + 1];
  for (i = 0; i < n; i++) {
    cin >> x >> y;
    if (x <= m) {
      v[x].push_back(y);
    }
  }
  priority_queue<int> pq;

  for (i = 1; i <= m; i++) {
    for (j = 0; j < v[i].size(); j++) {
      k = v[i][j];
      pq.push(k);
    }
    if (!pq.empty()) {
      p = p + pq.top();
      pq.pop();
    }
  }
  cout << p << endl;
  return 0;
}
Problem p02948 (C++)

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

int main() {
  int N, M;
  cin >> N >> M;
  Graph G(M);
  rep(i, N) {
    int A, B;
    cin >> A >> B;
    A--;
    G[A].push_back(B);
  }
  ll sum = 0;
  priority_queue<ll> list;
  rep(i, M) {
    if (G[i].size() > 0) {
      rep(j, G[i].size()) { list.push(G[i][j]); }
    }
    if (list.size() > 0) {
      sum = sum + list.top();
      list.pop();
    }
  }
  cout << sum << endl;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  Graph G(M);
  rep(i, N) {
    int A, B;
    cin >> A >> B;
    if (A <= M) {
      A--;
      G[A].push_back(B);
    }
  }
  ll sum = 0;
  priority_queue<ll> list;
  rep(i, M) {
    if (G[i].size() > 0) {
      rep(j, G[i].size()) { list.push(G[i][j]); }
    }
    if (list.size() > 0) {
      sum = sum + list.top();
      list.pop();
    }
  }
  cout << sum << endl;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define print(x) cout << (x) << '\n'
#define pe(x) cout << (x) << " "
#define DEBUG(x) cout << #x << ": " << x << endl
#define pb push_back
#define mp make_pair
#define MOD 1000000007 // 10^9+7
#define fi first
#define sc second
using ll = long long;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vstr = vector<string>;
void yes(bool c) {
  if (c)
    print("Yes");
  else
    print("No");
};

int N, M;
ll ans = 0;

void solve() {
  cin >> N >> M;
  vector<vector<int>> d(51);
  rep(i, N) {
    int a, b;
    cin >> a >> b;
    d[a].pb(b);
  }

  priority_queue<int> pq;
  per(i, M) {
    for (auto t : d[M - i]) {
      pq.push(t);
    }
    if (!pq.empty()) {
      ans += pq.top();
      pq.pop();
    }
  }
  print(ans);
}

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  // int q; cin >> q;
  // while (q--)
  solve();
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define print(x) cout << (x) << '\n'
#define pe(x) cout << (x) << " "
#define DEBUG(x) cout << #x << ": " << x << endl
#define pb push_back
#define mp make_pair
#define MOD 1000000007 // 10^9+7
#define fi first
#define sc second
using ll = long long;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vstr = vector<string>;
void yes(bool c) {
  if (c)
    print("Yes");
  else
    print("No");
};

int N, M;
ll ans = 0;

void solve() {
  cin >> N >> M;
  vector<vector<int>> d(100000);
  rep(i, N) {
    int a, b;
    cin >> a >> b;
    d[a].pb(b);
  }

  priority_queue<int> pq;
  per(i, M) {
    for (auto t : d[M - i]) {
      pq.push(t);
    }
    if (!pq.empty()) {
      ans += pq.top();
      pq.pop();
    }
  }
  print(ans);
}

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  // int q; cin >> q;
  // while (q--)
  solve();
  return 0;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;

template <typename T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}
template <typename T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}

int in() {
  int x;
  scanf("%d", &x);
  return x;
}
ll lin() {
  ll x;
  scanf("%lld", &x);
  return x;
}

int main() {
  ll n, m;
  cin >> n >> m;
  VVL b(m);
  REP(i, n) {
    ll x = in() - 1, y = in();
    b[x].push_back(y);
  }
  priority_queue<ll> que;
  ll ans = 0;
  REP(i, m) {
    for (ll x : b[i])
      que.push(x);
    if (!que.empty()) {
      ans += que.top();
      que.pop();
    }
  }
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;

template <typename T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}
template <typename T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}

int in() {
  int x;
  scanf("%d", &x);
  return x;
}
ll lin() {
  ll x;
  scanf("%lld", &x);
  return x;
}

int main() {
  ll n, m;
  cin >> n >> m;
  VVL b(m);
  REP(i, n) {
    ll x = in() - 1, y = in();
    if (x < m)
      b[x].push_back(y);
  }
  priority_queue<ll> que;
  ll ans = 0;
  REP(i, m) {
    for (ll x : b[i])
      que.push(x);
    if (!que.empty()) {
      ans += que.top();
      que.pop();
    }
  }
  cout << ans << endl;

  return 0;
}
Problem p02948 (C++)

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

#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int N, M;
pii AB[100100];

signed main() {
  cin >> N >> M;
  rep(i, N) { cin >> AB[i].first >> AB[i].second; }
  sort(AB, AB + N);
  priority_queue<int> pque;
  int k = 0;
  int ans = 0;
  for (int i = 1; i <= M; ++i) {
    // i日前
    while (AB[k].first <= i) {
      pque.push(AB[k].second);
      k++;
    }
    if (!pque.empty()) {
      ans += pque.top();
      pque.pop();
    }
  }
  cout << ans << endl;
  return 0;
}


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

#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int N, M;
pii AB[100100];

signed main() {
  cin >> N >> M;
  rep(i, N) { cin >> AB[i].first >> AB[i].second; }
  sort(AB, AB + N);
  priority_queue<int> pque;
  int k = 0;
  int ans = 0;
  for (int i = 1; i <= M; ++i) {
    // i日前
    while (k < N && AB[k].first <= i) {
      pque.push(AB[k].second);
      k++;
    }
    if (!pque.empty()) {
      ans += pque.top();
      pque.pop();
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02948 (C++)

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

int main() {
  int n, m, a, b;
  vector<pair<int, int>> p;
  priority_queue<int> q;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    p.push_back(make_pair(a, b));
  }
  sort(p.begin(), p.end());
  auto itr = p.begin();
  ll ans = 0;
  for (int i = 1; i <= m; i++) {
    while ((*itr).first <= i) {
      q.push((*itr).second);
      itr++;
    }
    if (!q.empty()) {
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << endl;
}

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

int main() {
  int n, m, a, b;
  vector<pair<int, int>> p;
  priority_queue<int> q;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    p.push_back(make_pair(a, b));
  }
  sort(p.begin(), p.end());
  auto itr = p.begin();
  ll ans = 0;
  for (int i = 1; i <= m; i++) {
    while ((*itr).first <= i && itr != p.end()) {
      q.push((*itr).second);
      itr++;
    }
    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;

const int maxn = 510;

typedef long long ll;

typedef pair<int, int> P;

P a[maxn];

priority_queue<int> q;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i].first >> a[i].second;
  }

  sort(a, a + n);
  int j = 0;
  for (int i = 1; i <= m; i++) {
    for (; j < n; j++) {
      if (a[j].first > i) {
        break;
      }
      q.push(a[j].second);
    }
    if (!q.empty()) {
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

const int maxn = 1e5 + 5;

typedef long long ll;

typedef pair<int, int> P;

P a[maxn];

priority_queue<int> q;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i].first >> a[i].second;
  }

  sort(a, a + n);
  int j = 0;
  for (int i = 1; i <= m; i++) {
    for (; j < n; j++) {
      if (a[j].first > i) {
        break;
      }
      q.push(a[j].second);
    }
    if (!q.empty()) {
      ans += q.top();
      q.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;
using ll = long long;
using P = pair<int, int>;
#define chmax(x, y) x = max(x, y);

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> jobs(m);
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    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;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define chmax(x, y) x = max(x, y);

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;
  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;
using ll = long long;

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

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

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