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

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> jobs(m + 1);
  int a, b;
  rep(i, n) {
    cin >> a >> b;
    jobs[m - a].push_back(b);
  }
  ll ans = 0;
  priority_queue<int> q;
  for (int i = m - 1; i >= 0; i--) {
    for (auto &&job : jobs[i]) {
      q.push(job);
    }
    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)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <string.h>
using namespace std;
using pii = pair<int, int>;
const int N = 1e5 + 1;
pii arr[N];

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i)
    scanf("%d%d", &(arr[i].first), &(arr[i].second));
  sort(arr, arr + n);
  priority_queue<int> q;
  int ans = 0;
  for (int i = 1, j = 0; i <= m; ++i) {
    while (j < n && arr[j].first <= i)
      q.push(arr[j++].second);
    ans += q.top();
    q.pop();
  }
  printf("%d\n", ans);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <string.h>
using namespace std;
using pii = pair<int, int>;
const int N = 1e5 + 1;
pii arr[N];

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i)
    scanf("%d%d", &(arr[i].first), &(arr[i].second));
  sort(arr, arr + n);
  priority_queue<int> q;
  int ans = 0;
  for (int i = 1, j = 0; i <= m; ++i) {
    while (j < n && arr[j].first <= i)
      q.push(arr[j++].second);
    if (!q.empty()) {
      ans += q.top();
      q.pop();
    }
  }
  printf("%d\n", ans);
  return 0;
}
Problem p02948 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x) cerr << #x << " = " << (x) << endl;
#define DEBUG(x)                                                               \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge {
  int u, v;
  ll w;
};

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> p(n);
  priority_queue<int> q;

  REP(i, n) {
    int a, b;
    cin >> a >> b;
    p[i] = make_pair(a, b);
  }
  ASC(p);
  int ans = 0;
  int idx = 0;
  FOR(i, 1, m + 1) {
    for (int l = idx; l < n; l++) {
      if (p[l].first <= i) {
        q.push(p[l].second);
        idx++;
      }
    }
    if (!q.empty()) {
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x) cerr << #x << " = " << (x) << endl;
#define DEBUG(x)                                                               \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge {
  int u, v;
  ll w;
};

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> p(n);
  priority_queue<int> q;

  REP(i, n) {
    int a, b;
    cin >> a >> b;
    p[i] = make_pair(a, b);
  }
  ASC(p);
  int ans = 0;
  int idx = 0;
  FOR(i, 1, m + 1) {
    for (int l = idx; l < n; l++) {
      if (p[l].first > i)
        break;
      q.push(p[l].second);
      idx++;
    }
    if (!q.empty()) {
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << endl;
}
Problem p02948 (C++)

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

using namespace std;

int main() {
  int n, m, a, b;
  cin >> n >> m;
  vector<int> v[m + 9];
  int mx[m + 9];
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    v[a].push_back(b);
  }
  long long cnt = 0;
  priority_queue<long long> Q;
  for (int i = 1; i <= m; i++) {
    if (!v[i].empty()) {
      for (int j = 0; j < v[i].size(); j++) {
        Q.push(v[i][j]);
      }
    }
    if (!Q.empty()) {
      cnt += Q.top();
      Q.pop();
    }
  }
  cout << cnt << endl;
}

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

using namespace std;

int main() {
  int n, m, a, b;
  cin >> n >> m;
  vector<int> v[100009];
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    v[a].push_back(b);
  }
  long long cnt = 0;
  priority_queue<long long> Q;
  for (int i = 1; i <= m; i++) {
    if (!v[i].empty()) {
      for (int j = 0; j < v[i].size(); j++) {
        Q.push(v[i][j]);
      }
    }
    if (!Q.empty()) {
      cnt += Q.top();
      Q.pop();
    }
  }
  cout << cnt << endl;
}
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>> job(m + 1);
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    job[a].push_back(b);
  }

  int ans = 0;
  priority_queue<int, vector<int>, less<int>> work;
  for (int i = 1; i <= m; i++) {
    for (int next : job[i]) {
      work.push(next);
    }
    if (!work.empty()) {
      ans += work.top();
      work.pop();
    }
  }

  cout << ans << endl;

  return 0;
}

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

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

  vector<vector<int>> job(100001);
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    job[a].push_back(b);
  }

  int ans = 0;
  priority_queue<int, vector<int>, less<int>> work;
  for (int i = 1; i <= m; i++) {
    for (int next : job[i]) {
      work.push(next);
    }
    if (!work.empty()) {
      ans += work.top();
      work.pop();
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p02948 (C++)

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

#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream &operator>>(istream &I, vector<T> &v) {
  for (T &e : v)
    I >> e;
  return I;
}
template <class T> ostream &operator<<(ostream &O, const vector<T> &v) {
  for (const T &e : v)
    O << e << ' ';
  return O;
}

void _main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> when((int)1e5 + 1);
  m++;

  int from = 1;
  while (n--) {
    int time, cost;
    cin >> time >> cost;
    when[m - time].emplace_back(cost);
  }

  ll ans = 0;
  priority_queue<int> pq;

  for (int time = m; time >= 1; time--) {
    while (when[time].size()) {
      pq.emplace(when[time].back());
      when[time].pop_back();
    }
    if (pq.size())
      ans += pq.top(), pq.pop();
  }

  cout << ans;
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  //        freopen("input.txt", "r", stdin);
  int _t = 1;
  //        cin >> _t;
  while (_t--)
    _main();
  return 0;
}

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

#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream &operator>>(istream &I, vector<T> &v) {
  for (T &e : v)
    I >> e;
  return I;
}
template <class T> ostream &operator<<(ostream &O, const vector<T> &v) {
  for (const T &e : v)
    O << e << ' ';
  return O;
}

void _main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> when((int)1e5 + 1);
  m++;

  int from = 1;
  while (n--) {
    int time, cost;
    cin >> time >> cost;
    if (m - time >= 1)
      when[m - time].emplace_back(cost);
  }

  ll ans = 0;
  priority_queue<int> pq;

  for (int time = m; time >= 1; time--) {
    while (when[time].size()) {
      pq.emplace(when[time].back());
      when[time].pop_back();
    }
    if (pq.size())
      ans += pq.top(), pq.pop();
  }

  cout << ans;
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  //        freopen("input.txt", "r", stdin);
  int _t = 1;
  //        cin >> _t;
  while (_t--)
    _main();
  return 0;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < int(a); ++i)
#define REP(i, a, b) for (int i = int(a); i < int(b); ++i)
#define INF 10000000
using ll = long long;
using itn = int;
using namespace std;
using Graph = vector<vector<int>>;
int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }
int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> work(10);
  rep(i, N) {
    int a, b;
    cin >> a >> b;
    work.at(a).push_back(b);
  }

  ll ans = 0;
  priority_queue<int> q;
  for (int day = 0; day <= M; day++) {
    for (int i : work.at(day)) {
      q.push(i);
    }
    if (q.size() != 0) {
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < int(a); ++i)
#define REP(i, a, b) for (int i = int(a); i < int(b); ++i)
#define INF 10000000
using ll = long long;
using itn = int;
using namespace std;
using Graph = vector<vector<int>>;
int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }
int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> work(10e5 + 10);
  rep(i, N) {
    int a, b;
    cin >> a >> b;
    work.at(a).push_back(b);
  }

  ll ans = 0;
  priority_queue<int> q;
  for (int day = 0; day <= M; day++) {
    for (int i : work.at(day)) {
      q.push(i);
    }
    if (q.size() != 0) {
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << endl;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln = '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rept(i, j, n) for (int i = (j); i < (n); i++)
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;
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> P(100100);
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    P[m - a].push_back(b); // m-a日まで受注可能
  }
  priority_queue<int> que;
  ll res = 0;
  for (int i = m; i >= 0; i--) {
    for (auto p : P[i]) {
      que.push(p);
    }
    if (!que.empty()) {
      res += que.top();
      que.pop();
    }
  }
  cout << res << ln;
}


Fixed submission:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln = '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rept(i, j, n) for (int i = (j); i < (n); i++)
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;
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> P(100100);
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    if (m - a >= 0)
      P[m - a].push_back(b); // m-a日まで受注可能
  }
  priority_queue<int> que;
  ll res = 0;
  for (int i = m; i >= 0; i--) {
    for (auto p : P[i]) {
      que.push(p);
    }
    if (!que.empty()) {
      res += que.top();
      que.pop();
    }
  }
  cout << res << ln;
}
Problem p02948 (C++)

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

using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll, ll> P;
typedef vector<P> vp;
#define rep(i, a, b) for (ll i = (a); i < (b); ++i)
#define drep(i, a, b) for (ll i = (a); i >= (b); --i)
#define SIZE(a) int((a).size())
#define out(a) cout << (a) << endl;
const int INF = INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;
ll roundd(ll x, ll n) {
  if (x > n) {
    return x % n;
  } else if (x < 0) {
    return x % n + n;
  } else
    return x;
}

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


Fixed submission:
#include "bits/stdc++.h"
#include "math.h"

using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll, ll> P;
typedef vector<P> vp;
#define rep(i, a, b) for (ll i = (a); i < (b); ++i)
#define drep(i, a, b) for (ll i = (a); i >= (b); --i)
#define SIZE(a) int((a).size())
#define out(a) cout << (a) << endl;
const int INF = INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;
ll roundd(ll x, ll n) {
  if (x > n) {
    return x % n;
  } else if (x < 0) {
    return x % n + n;
  } else
    return x;
}

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <set>
using namespace std;
struct jb {
  int a, b;
  friend bool operator<(jb x, jb y) { return x.a > y.a; };
} g[100010];
int n, m, k, l, ans = 0, f[100010];
set<int> s;
_Rb_tree_const_iterator<int> p;
int mx(int x, int y) { return x > y ? x : y; }
int mn(int x, int y) { return x < y ? x : y; }
void read(int &x) {
  char c;
  x = 0;
  while (c > '9' || c < '0')
    c = getchar();
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
}
int main() {
  // freopen("ted.in","r",stdin);
  read(n);
  read(m);
  for (int i = 0; i < n; i++) {
    read(g[i].b);
    read(g[i].a);
  }
  sort(g, g + n);
  for (int i = 0; i <= m; i++)
    s.insert(i);
  for (int i = 0; i < n; i++) {
    g[i].b = m - g[i].b;
    p = lower_bound(s.begin(), s.end(), g[i].b);
    if (p != s.begin() && (*p) > g[i].b)
      p--;
    if ((*p) <= g[i].b) {
      ans += g[i].a;
      s.erase(*p);
    }
  }
  printf("%d\n", ans);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <set>
using namespace std;
struct jb {
  int a, b;
  friend bool operator<(jb x, jb y) { return x.a > y.a; };
} g[100010];
int n, m, k, l, ans = 0, f[100010];
set<int> s;
_Rb_tree_const_iterator<int> p;
int mx(int x, int y) { return x > y ? x : y; }
int mn(int x, int y) { return x < y ? x : y; }
void read(int &x) {
  char c;
  x = 0;
  while (c > '9' || c < '0')
    c = getchar();
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
}
int main() {
  // freopen("ted.in","r",stdin);
  read(n);
  read(m);
  for (int i = 0; i < n; i++) {
    read(g[i].b);
    read(g[i].a);
  }
  sort(g, g + n);
  for (int i = 0; i <= m; i++)
    s.insert(i);
  for (int i = 0; i < n; i++) {
    g[i].b = m - g[i].b;
    p = s.lower_bound(g[i].b);
    if (p != s.begin() && (*p) > g[i].b)
      p--;
    if ((*p) <= g[i].b) {
      ans += g[i].a;
      s.erase(*p);
    }
  }
  printf("%d\n", ans);
  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 < n; i++)

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

  vector<pair<int, int>> A(N);
  rep(i, N) {
    cin >> A[i].first;
    cin >> A[i].second;
  }
  sort(A.begin(), A.end());

  long long ans = 0;
  int j = 0;
  priority_queue<int> B;
  rep(i, M) {
    while (A[j].first <= i + 1 && j < N) {
      B.push(A[j].second);
      j++;
    }
    if (j != 0) {
      ans += B.top();
      B.pop();
    }
  }
  cout << ans;
}

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

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

  vector<pair<int, int>> A(N);
  rep(i, N) {
    cin >> A[i].first;
    cin >> A[i].second;
  }
  sort(A.begin(), A.end());

  long long ans = 0;
  int j = 0;
  priority_queue<int> B;
  rep(i, M) {
    while (A[j].first <= i + 1 && j < N) {
      B.push(A[j].second);
      j++;
    }
    if (!B.empty()) {
      ans += B.top();
      B.pop();
    }
  }
  cout << ans;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;
#define REP(i, a) for (int i = 0; i < (a); i++)
#define ALL(a) (a).begin(), (a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using Graph = vector<vector<int>>;
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
  return (x + y - 1) / y;
}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
  long long int m = number1;
  long long int n = number2;

  if (number2 > number1) {
    m = number2;
    n = number1;
  }
  long long int s = -1;
  while (s != 0) {
    s = m % n;
    m = n;
    n = s;
  }
  return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
  long long int m = number1;
  long long int n = number2;
  return m / lcm(m, n) * n;
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> s(10020);
  long long int sum = 0;
  priority_queue<int> q;
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    if (a > M) {
      continue;
    }
    s[a].push_back(b);
  }
  for (int i = 1; i <= M; i++) {
    int max = 0;
    for (int j = 0; j < s[i].size(); j++) {
      if (s[i][j] > max) {
        q.push(max);
        max = s[i][j];
      } else {
        q.push(s[i][j]);
      }
    }
    if (!q.empty()) {
      if (q.top() > max) {
        q.push(max);
        max = q.top();
        q.pop();
      }
    }
    sum = max + sum;
  }
  cout << sum;
}

Fixed submission:
#include "bits/stdc++.h"
using namespace std;
#define REP(i, a) for (int i = 0; i < (a); i++)
#define ALL(a) (a).begin(), (a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using Graph = vector<vector<int>>;
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
  return (x + y - 1) / y;
}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
  long long int m = number1;
  long long int n = number2;

  if (number2 > number1) {
    m = number2;
    n = number1;
  }
  long long int s = -1;
  while (s != 0) {
    s = m % n;
    m = n;
    n = s;
  }
  return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
  long long int m = number1;
  long long int n = number2;
  return m / lcm(m, n) * n;
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> s(100020);
  long long int sum = 0;
  priority_queue<int> q;
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    if (a > M) {
      continue;
    }
    s[a].push_back(b);
  }
  for (int i = 1; i <= M; i++) {
    int max = 0;
    for (int j = 0; j < s[i].size(); j++) {
      if (s[i][j] > max) {
        q.push(max);
        max = s[i][j];
      } else {
        q.push(s[i][j]);
      }
    }
    if (!q.empty()) {
      if (q.top() > max) {
        q.push(max);
        max = q.top();
        q.pop();
      }
    }
    sum = max + sum;
  }
  cout << sum;
}
Problem p02948 (C++)

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> w(n);
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    w.at(i) = make_pair(a, b);
  }

  sort(w.begin(), w.end());

  int index = 0;
  priority_queue<int> q;
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    while (index < n && w.at(index).first <= i)
      q.push(w.at(index++).second);

    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;
  vector<pair<int, int>> w(n);
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    w.at(i) = make_pair(a, b);
  }

  sort(w.begin(), w.end());

  int index = 0;
  priority_queue<int> q;
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    while (index < n && w.at(index).first <= i)
      q.push(w.at(index++).second);

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9;
const ll mod = 1e9 + 7;
typedef pair<int, int> P;
typedef pair<pair<int, int>, pair<int, int>> PP;
#define rep(i, N) for (int i = 0; i < N; i++)

int main() {
  int n, m;
  cin >> n >> m;
  int a[n], b[n];
  vector<P> p(n);
  priority_queue<int> pq;
  rep(i, n) {
    cin >> a[i] >> b[i];
    //        p[i]=make_pair(a[i],b[i]);
    p[i] = make_pair(a[i], b[i]);
  }
  sort(p.begin(), p.end());
  int now = 1;
  ll ans = 0;
  int c = 0;
  for (int i = 1; i <= m; i++) {
    //        cout<<i<<endl;
    while (i == p[0].first) {
      pq.push(p[0].second);
      p.erase(p.begin());
      if (p.empty())
        break;
    }
    if (pq.empty())
      continue;
    ans += pq.top();
    pq.pop();
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9;
const ll mod = 1e9 + 7;
typedef pair<int, int> P;
typedef pair<pair<int, int>, pair<int, int>> PP;
#define rep(i, N) for (int i = 0; i < N; i++)

int main() {
  int n, m;
  cin >> n >> m;
  int a[n], b[n];
  vector<P> p(n);
  priority_queue<int> pq;
  rep(i, n) {
    cin >> a[i] >> b[i];
    //        p[i]=make_pair(a[i],b[i]);
    p[i] = make_pair(a[i], b[i]);
  }
  sort(p.begin(), p.end());
  int now = 1;
  ll ans = 0;
  int c = 0;
  for (int i = 1; i <= m; i++) {
    //        cout<<i<<endl;
    while (i == p[c].first) {
      pq.push(p[c].second);
      c++;
      // p.erase(p.begin());
      // if(p.empty())break;
    }
    if (pq.empty())
      continue;
    ans += pq.top();
    pq.pop();
  }
  cout << ans << endl;
}
Problem p02948 (C++)

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

using namespace std;

priority_queue<int> q;

vector<vector<int>> jobs;

int main(void) {
  int n, m;
  cin >> n >> m;
  jobs = vector<vector<int>>(m + 1);
  for (int a = 0; a < n; a = a + 1) {
    int ai, bi;
    cin >> ai >> bi;
    jobs[ai].push_back(bi);
  }

  int ans = 0;

  for (int a = 1; a <= m; a = a + 1) {
    for (auto day : jobs[a])
      q.push(day);

    if (!q.empty()) {
      ans += q.top();
      q.pop();
    }
  }

  cout << ans;

  return 0;
}

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

using namespace std;

priority_queue<int> q;

vector<vector<int>> jobs;

int main(void) {
  int n, m;
  cin >> n >> m;
  jobs = vector<vector<int>>(100001);
  for (int a = 0; a < n; a = a + 1) {
    int ai, bi;
    cin >> ai >> bi;
    jobs[ai].push_back(bi);
  }

  int ans = 0;

  for (int a = 1; a <= m; a = a + 1) {
    for (auto day : jobs[a])
      q.push(day);

    if (!q.empty()) {
      ans += q.top();
      q.pop();
    }
  }

  cout << ans;

  return 0;
}
Problem p02948 (C++)

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

using namespace std;
typedef long long ll;

// マクロ
// forループ関係
// 引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
// Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
// xにはvectorなどのコンテナ
#define ALL(x) x.begin(), x.end() // sortなどの引数を省略したい
#define SIZE(x) ll(x.size())      // sizeをsize_tからllに直しておく
// 定数
#define INF 1000000000000 // 10^12:極めて大きい値,∞
#define MOD 1000000007    // 10^9+7:合同式の法
#define MAXR 100000 // 10^5:配列の最大のrange(素数列挙などで使用)
// 略記
#define PB emplace_back // vectorヘの挿入
#define MP make_pair    // pairのコンストラクタ
#define F first         // pairの一つ目の要素
#define S second        // pairの二つ目の要素
#define Umap unordered_map
#define Uset unordered_set

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> a(n), b(n);
  REP(i, n) cin >> a[i] >> b[i];
  vector<vector<ll>> score(10001);
  priority_queue<ll> score_all;
  REP(i, n) score[a[i]].PB(b[i]);
  ll ans = 0;
  REP(i, m) {
    while (!score[i + 1].empty()) {
      score_all.push(score[i + 1].back());
      score[i + 1].pop_back();
    }
    if (score_all.empty())
      continue;
    ans += score_all.top();
    score_all.pop();
  }
  cout << ans;
  return 0;
}

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

using namespace std;
typedef long long ll;

// マクロ
// forループ関係
// 引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
// Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
// xにはvectorなどのコンテナ
#define ALL(x) x.begin(), x.end() // sortなどの引数を省略したい
#define SIZE(x) ll(x.size())      // sizeをsize_tからllに直しておく
// 定数
#define INF 1000000000000 // 10^12:極めて大きい値,∞
#define MOD 1000000007    // 10^9+7:合同式の法
#define MAXR 100000 // 10^5:配列の最大のrange(素数列挙などで使用)
// 略記
#define PB emplace_back // vectorヘの挿入
#define MP make_pair    // pairのコンストラクタ
#define F first         // pairの一つ目の要素
#define S second        // pairの二つ目の要素
#define Umap unordered_map
#define Uset unordered_set

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> a(n), b(n);
  REP(i, n) cin >> a[i] >> b[i];
  vector<vector<ll>> score(MAXR + 1);
  priority_queue<ll> score_all;
  REP(i, n) score[a[i]].PB(b[i]);
  ll ans = 0;
  REP(i, m) {
    while (!score[i + 1].empty()) {
      score_all.push(score[i + 1].back());
      score[i + 1].pop_back();
    }
    if (score_all.empty())
      continue;
    ans += score_all.top();
    score_all.pop();
  }
  cout << ans;
  return 0;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define INF 1000000007
#define LINF 8000000000000000007
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X)                                                                 \
  {}
#define ARDEB(i, X)                                                            \
  {}
#define END                                                                    \
  {}
#endif
typedef pair<int, int> P;
struct edge {
  int to, cost;
};

typedef long long ll;

using namespace std;

int ans, ans2;
int n, m;
P p[111111];

signed main() {

  cin >> n >> m;
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    p[i] = P(a, b);
  }
  sort(p, p + n);
  priority_queue<int> que;
  int j = 0;
  rep(i, m) {
    while (p[j].first <= i + 1) {
      que.push(p[j].second);
      j++;
    }
    if (que.size()) {
      ans += que.top();
      que.pop();
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define INF 1000000007
#define LINF 8000000000000000007
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X)                                                                 \
  {}
#define ARDEB(i, X)                                                            \
  {}
#define END                                                                    \
  {}
#endif
typedef pair<int, int> P;
struct edge {
  int to, cost;
};

typedef long long ll;

using namespace std;

int ans, ans2;
int n, m;
P p[111111];

signed main() {

  cin >> n >> m;
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    p[i] = P(a, b);
  }
  sort(p, p + n);
  priority_queue<int> que;
  int j = 0;
  rep(i, m) {
    while (p[j].first <= i + 1 && j < n) {
      que.push(p[j].second);
      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;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main() {
  ll a, b, n, m;
  in2(n, m);
  a = b = 0;
  vector<pair<ll, ll>> c(n);
  rep(i, n) in2(c[i].first, c[i].second);
  sort(all(c));
  priority_queue<ll> d;
  rep2(i, 1, m + 1) {
    if (b < n) {
      while (c[b].first == i) {
        d.push(c[b].second);
        b++;
        if (b == n)
          break;
      }
    }
    a += d.top();
    d.pop();
  }
  out(a);
  memi;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main() {
  ll a, b, n, m;
  in2(n, m);
  a = b = 0;
  vector<pair<ll, ll>> c(n);
  rep(i, n) in2(c[i].first, c[i].second);
  sort(all(c));
  priority_queue<ll> d;
  rep2(i, 1, m + 1) {
    if (b < n) {
      while (c[b].first == i) {
        d.push(c[b].second);
        b++;
        if (b == n)
          break;
      }
    }
    if (!d.empty()) {
      a += d.top();
      d.pop();
    }
  }
  out(a);
  memi;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e5 + 10;
int a[N], b[N], v[N];
typedef pair<int, int> pa;
vector<int> dead[N];

int main() {
  int n, m;
  cin >> n >> m;
  multiset<int> st;
  m++;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    dead[m - a[i]].push_back(b[i]);
  }
  ll ans = 0;
  for (int i = m; i >= 1; i--) {
    for (int x : dead[i]) {
      st.insert(x);
    }
    if (!st.empty()) {
      auto it = prev(st.end());
      ans += *it;
      st.erase(it);
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e5 + 10;
int a[N], b[N], v[N];
typedef pair<int, int> pa;
vector<int> dead[N];

int main() {
  int n, m;
  cin >> n >> m;
  multiset<int> st;
  m++;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    if (m - a[i] <= 0)
      continue;
    dead[m - a[i]].push_back(b[i]);
  }
  ll ans = 0;
  for (int i = m; i >= 1; i--) {
    for (int x : dead[i]) {
      st.insert(x);
    }
    if (!st.empty()) {
      auto it = prev(st.end());
      ans += *it;
      st.erase(it);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02948 (C++)

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

using namespace std;

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(0);

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

  priority_queue<long long> q;
  long long ans = 0;

  for (int i = 0; i < m; i++) {
    for (int j = 0; j < a[i].size(); j++)
      q.push(a[i][j]);
    if (!q.empty()) {
      ans += q.top();
      q.pop();
    }
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
// D - Summer Vacation
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(0);

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

  priority_queue<long long> q;
  long long ans = 0;

  for (int i = 0; i < m; i++) {
    for (int j = 0; j < a[i].size(); j++)
      q.push(a[i][j]);
    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>
using namespace std;
#define int long long
const int maxn = 5e5 + 5;
inline int read() {
  char c = getchar();
  int t = 0, f = 1;
  while (!isdigit(c)) {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    t = (t << 3) + (t << 1) + (c ^ 48);
    c = getchar();
  }
  return t * f;
}
int n, m;
struct node {
  int a, b;
} a[maxn];
bool cmp(node a, node b) { return a.a < b.a; }
priority_queue<int, vector<int>, greater<int>> q;
signed main() {
  n = read(), m = read();
  for (int i = 1; i <= n; i++) {
    a[i].a = read(), a[i].b = read();
    a[i].a = m - a[i].a + 1;
  }
  sort(a + 1, a + 1 + n, cmp);
  int sum = 0, sz = 0;
  for (int i = 1; i <= n; i++) {
    if (sz < a[i].a) {
      q.push(a[i].b);
      sum += a[i].b;
      sz++;
    } else {
      int alfa = q.top();
      if (alfa < a[i].b) {
        q.pop();
        sum -= alfa;
        sum += a[i].b;
        q.push(a[i].b);
      }
    }
  }
  printf("%lld\n", sum);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 5e5 + 5;
inline int read() {
  char c = getchar();
  int t = 0, f = 1;
  while (!isdigit(c)) {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    t = (t << 3) + (t << 1) + (c ^ 48);
    c = getchar();
  }
  return t * f;
}
int n, m;
struct node {
  int a, b;
} a[maxn];
bool cmp(node a, node b) { return a.a < b.a; }
priority_queue<int, vector<int>, greater<int>> q;
signed main() {
  n = read(), m = read();
  for (int i = 1; i <= n; i++) {
    a[i].a = read(), a[i].b = read();
    a[i].a = m - a[i].a + 1;
  }
  sort(a + 1, a + 1 + n, cmp);
  int sum = 0, sz = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i].a <= 0)
      continue;
    if (sz < a[i].a) {
      q.push(a[i].b);
      sum += a[i].b;
      sz++;
    } else {
      int alfa = q.top();
      if (alfa < a[i].b) {
        q.pop();
        sum -= alfa;
        sum += a[i].b;
        q.push(a[i].b);
      }
    }
  }
  printf("%lld\n", sum);
  return 0;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define vout(x) rep(i, x.size()) cout << x[i] << " "
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int, int>;
const int inf = 1e9;
const ll inf_l = 1LL << 62;
const int MAX = 1e5;

int main() {
  int n, m;
  cin >> n >> m;
  vvint data(m);
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    a--;
    data[a].push_back(b);
  }
  priority_queue<int> q;
  int ans = 0;
  rep(i, m) {
    rep(j, data[i].size()) { q.push(data[i][j]); }
    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 < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define vout(x) rep(i, x.size()) cout << x[i] << " "
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int, int>;
const int inf = 1e9;
const ll inf_l = 1LL << 62;
const int MAX = 1e5;

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
const int maxn = 110000;
const int mod = 1000000007;
using namespace std;
int n, m, ans;
struct node {
  int time, v;
} a[maxn];
bool cmp(node a, node b) { return a.time > b.time; }
priority_queue<int, vector<int>, greater<int>> p;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &a[i].time, &a[i].v);
  }
  sort(a + 1, a + 1 + n, cmp);
  for (int i = 1; i <= n; i++) {
    if (a[i].time <= m - p.size()) {
      p.push(a[i].v);
    } else {
      int t = p.top();
      if (a[i].time <= m - p.size() + 1) {
        if (a[i].v > t) {
          p.pop();
          p.push(a[i].v);
        }
      }
    }
  }
  while (p.size()) {
    ans += p.top();
    p.pop();
  }
  printf("%d", ans);
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
const int maxn = 110000;
const int mod = 1000000007;
using namespace std;
int n, m, ans;
struct node {
  int time, v;
} a[maxn];
bool cmp(node a, node b) { return a.time > b.time; }
priority_queue<int, vector<int>, greater<int>> p;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &a[i].time, &a[i].v);
  }
  sort(a + 1, a + 1 + n, cmp);
  for (int i = 1; i <= n; i++) {
    if (a[i].time <= m - p.size()) {
      p.push(a[i].v);
    } else {
      int t = p.top();
      if (a[i].time <= m - p.size() + 1 && p.size()) {
        if (a[i].v > t) {
          p.pop();
          p.push(a[i].v);
        }
      }
    }
  }
  while (p.size()) {
    ans += p.top();
    p.pop();
  }
  printf("%d", ans);
}
Problem p02948 (C++)

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

int main() {
  unsigned int N, M;
  std::cin >> N >> M;

  std::vector<std::vector<unsigned int>> day_jobs(100000);
  for (unsigned int i = 0; i < N; ++i) {
    unsigned int a, b;
    std::cin >> a >> b;
    day_jobs.at(a).push_back(b);
  }

  std::priority_queue<unsigned int> job_queue;
  unsigned long long sum = 0;
  for (unsigned int i = 1; i <= M; ++i) {
    for (auto x : day_jobs.at(i)) {
      job_queue.push(x);
    }
    if (!job_queue.empty()) {
      sum += job_queue.top();
      job_queue.pop();
    }
  }

  std::cout << sum << std::endl;

  return 0;
}


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

int main() {
  unsigned int N, M;
  std::cin >> N >> M;

  std::vector<std::vector<unsigned int>> day_jobs(100000 + 5);
  for (unsigned int i = 0; i < N; ++i) {
    unsigned int a, b;
    std::cin >> a >> b;
    day_jobs.at(a).push_back(b);
  }

  std::priority_queue<unsigned int> job_queue;
  unsigned long long sum = 0;
  for (unsigned int i = 1; i <= M; ++i) {
    for (auto x : day_jobs.at(i)) {
      job_queue.push(x);
    }
    if (!job_queue.empty()) {
      sum += job_queue.top();
      job_queue.pop();
    }
  }

  std::cout << sum << std::endl;

  return 0;
}
Problem p02948 (C++)

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

vector<long long> vp[230000];
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "rt", stdin);
  freopen("output.txt", "wt", stdout);
#endif
  long long n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    long long x, y;
    cin >> x >> y;
    vp[x].push_back(y);
  }
  long long ans = 0;
  priority_queue<long long> pq;
  for (int i = 1; i <= m; i++) {
    for (auto x : vp[i]) {
      pq.push(x);
    }
    if (!pq.empty()) {
      ans += pq.top();
      pq.pop();
    }
  }

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

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

vector<long long> vp[230000];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    long long x, y;
    cin >> x >> y;
    vp[x].push_back(y);
  }
  long long ans = 0;
  priority_queue<long long> pq;
  for (int i = 1; i <= m; i++) {
    for (auto x : vp[i]) {
      pq.push(x);
    }
    if (!pq.empty()) {
      ans += pq.top();
      pq.pop();
    }
  }

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

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

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

  long long n, m, ans = 0;
  cin >> n >> m;
  long long a[n], b[n];
  vector<long long> v[10005];
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    a[i]--;
    v[a[i]].push_back(b[i]);
  }
  priority_queue<long long> que;
  for (int i = 0; i < m; i++) {
    for (size_t j = 0; j < v[i].size(); j++) {
      que.push(v[i][j]);
    }
    if (!que.empty()) {
      ans += que.top();
      que.pop();
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#pragma target("avx")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

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

  long long n, m, ans = 0;
  cin >> n >> m;
  long long a[n], b[n];
  vector<long long> v[100005];
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    a[i]--;
    v[a[i]].push_back(b[i]);
  }
  priority_queue<long long> que;
  for (int i = 0; i < m; i++) {
    for (size_t j = 0; j < v[i].size(); j++) {
      que.push(v[i][j]);
    }
    if (!que.empty()) {
      ans += que.top();
      que.pop();
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

int main() {
  int n, m, i, a, b, ans = 0;
  priority_queue<int> q;
  cin >> n >> m;
  vector<vector<int>> v(m);
  for (i = 0; i < n; ++i) {
    cin >> a >> b;
    --a;
    v.at(a).push_back(b);
  }
  for (i = 0; i < m; ++i) {
    for (auto e : v.at(i))
      q.push(e);
    if (!q.empty()) {
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  int n, m, i, a, b, ans = 0;
  priority_queue<int> q;
  cin >> n >> m;
  vector<vector<int>> v(100000);
  for (i = 0; i < n; ++i) {
    cin >> a >> b;
    --a;
    v.at(a).push_back(b);
  }
  for (i = 0; i < m; ++i) {
    for (auto e : v.at(i))
      q.push(e);
    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>
using namespace std;
struct node {
  int a, b;
} p[100001];
bool cmp(node a, node b) { return a.a > b.a; }
int f[100001];
int getfa(int x) { return x == f[x] ? f[x] : f[x] = getfa(f[x]); }
int main() {
  int n, m;
  int ans = 0;
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    scanf("%d%d", &p[i].b, &p[i].a);
  sort(p + 1, p + n + 1, cmp);
  for (int i = 1; i <= m; i++)
    f[i] = i;
  for (int i = 1; i <= n; i++) {
    int t = getfa(m - p[i].b + 1);
    if (t != 0) {
      ans += p[i].a;
      f[t] = t - 1;
    }
  }
  printf("%d", ans);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
struct node {
  int a, b;
} p[100001];
bool cmp(node a, node b) { return a.a > b.a; }
int f[100001];
int getfa(int x) { return x == f[x] ? f[x] : f[x] = getfa(f[x]); }
int main() {
  int n, m;
  int ans = 0;
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    scanf("%d%d", &p[i].b, &p[i].a);
  sort(p + 1, p + n + 1, cmp);
  for (int i = 1; i <= m; i++)
    f[i] = i;
  for (int i = 1; i <= n; i++) {
    if (p[i].b > m)
      continue;
    int t = getfa(m - p[i].b + 1);
    if (t != 0) {
      ans += p[i].a;
      f[t] = t - 1;
    }
  }
  printf("%d", ans);
}