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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
const int maxn = 1e5 + 10;

int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 3) + (x << 1) + c - 48;
    c = getchar();
  }
  return x * f;
}

struct node {
  int x, y;
} a[maxn];
int cmp(node x, node y) {
  if (x.x == y.x)
    return x.y > y.y;
  return x.x < y.x;
}

priority_queue<int> q;
int main() {
  int k, m, n;
  n = read();
  m = read();
  for (register int i = 1; i <= n; i++) {
    a[i].x = read();
    a[i].y = read();
  }
  sort(a + 1, a + n + 1, cmp);
  int now = 1, ans = 0, t = 1;
  for (register int i = 1; i <= m; i++) {
    while (a[now].x <= i) {
      q.push(a[now].y);
      now++;
    }
    if (!q.empty()) {
      ans += q.top();
      q.pop();
    }
  }
  printf("%d\n", ans);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
const int maxn = 1e5 + 10;

int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 3) + (x << 1) + c - 48;
    c = getchar();
  }
  return x * f;
}

struct node {
  int x, y;
} a[maxn];
int cmp(node x, node y) {
  if (x.x == y.x)
    return x.y > y.y;
  return x.x < y.x;
}

priority_queue<int> q;
int main() {
  int k, m, n;
  n = read();
  m = read();
  for (register int i = 1; i <= n; i++) {
    a[i].x = read();
    a[i].y = read();
  }
  sort(a + 1, a + n + 1, cmp);
  int now = 1, ans = 0, t = 1;
  for (register int i = 1; i <= m; i++) {
    while (a[now].x <= i && now <= n) {
      q.push(a[now].y);
      now++;
    }
    if (!q.empty()) {
      ans += q.top();
      q.pop();
    }
  }
  printf("%d\n", ans);
  return 0;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
#define FI(i, a, b) for (int i = (a); i <= (b); ++i)
#define FD(i, b, a) for (int i = (b); i >= (a); --i)
#define DEBUG(x) cerr << #x << ": " << (x) << endl;

const int N = 1e5 + 5;
int n, m, a[N], b[N];
vector<int> g[N];

int main() {
  cin >> n >> m;
  FI(i, 1, n) scanf("%d%d", &a[i], &b[i]);
  FI(i, 1, n) g[m - a[i] + 1].push_back(i);
  FI(i, 1, m)
  sort(g[i].begin(), g[i].end(), [&](int x, int y) { return b[x] > b[y]; });
  int ans = 0;
  multiset<int> se;

  for (int i = 1; i <= m; i++) {
    for (auto j : g[i]) {
      se.insert(b[j]);
      ans += b[j];
      if (se.size() > i) {
        ans -= *se.begin();
        se.erase(se.begin());
      }
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
#define FI(i, a, b) for (int i = (a); i <= (b); ++i)
#define FD(i, b, a) for (int i = (b); i >= (a); --i)
#define DEBUG(x) cerr << #x << ": " << (x) << endl;

const int N = 1e5 + 5;
int n, m, a[N], b[N];
vector<int> g[N];

int main() {
  cin >> n >> m;
  FI(i, 1, n) scanf("%d%d", &a[i], &b[i]);
  FI(i, 1, n) {
    if (a[i] > m)
      continue;
    g[m - a[i] + 1].push_back(i);
  }
  FI(i, 1, m)
  sort(g[i].begin(), g[i].end(), [&](int x, int y) { return b[x] > b[y]; });
  int ans = 0;
  multiset<int> se;

  for (int i = 1; i <= m; i++) {
    for (auto j : g[i]) {
      se.insert(b[j]);
      ans += b[j];
      if (se.size() > i) {
        ans -= *se.begin();
        se.erase(se.begin());
      }
    }
  }
  cout << ans << endl;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int NN = 1e6 + 10;
typedef long long ll;

int N, M;
vector<int> ve[NN];
priority_queue<int> q;
int main() {
  //	freopen("test.in","r",stdin);
  cin >> N >> M;
  for (int i = 1; i <= N; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    ve[M - a + 1].push_back(
        b); // 表示M-a+1天之后不能做此份工作(也就是做了赚不到钱)
  }
  ll earn = 0;
  for (int i = M; i >= 1; i--) {
    for (int m : ve[i]) {
      q.push(m);
    }
    if (!q.empty()) {
      earn += q.top();
      q.pop();
    }
  }
  cout << earn << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int NN = 1e6 + 10;
typedef long long ll;

int N, M;
vector<int> ve[NN];
priority_queue<int> q;
int main() {
  //	freopen("test.in","r",stdin);
  cin >> N >> M;
  for (int i = 1; i <= N; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    if (a > M)
      continue;
    ve[M - a + 1].push_back(
        b); // 表示M-a+1天之后不能做此份工作(也就是做了赚不到钱)
  }
  ll earn = 0;
  for (int i = M; i >= 1; i--) {
    for (int m : ve[i]) {
      q.push(m);
    }
    if (!q.empty()) {
      earn += q.top();
      q.pop();
    }
  }
  cout << earn << endl;

  return 0;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define mod 1000000007
typedef long long ll;
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  ;
  vector<vector<int>> p(101000);
  int a, b;
  rep(i, N) {
    cin >> a >> b;
    p[a].pb(b);
  }
  rep(i, 101000) { sort(p[i].begin(), p[i].end(), greater<int>()); }
  int ans = 0;
  rep(i, N) ans += p[i][0];
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define mod 1000000007
typedef long long ll;
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  ;
  vector<vector<int>> p(101000);
  int a, b;
  rep(i, N) {
    cin >> a >> b;
    p[a].pb(b);
  }
  rep(i, 101000) { sort(p[i].begin(), p[i].end(), greater<int>()); }
  int ans = 0;
  priority_queue<int> q;
  for (int i = 1; i <= M; i++) {
    for (int j = 0; j < (int)p[i].size(); j++) {
      q.push(p[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 rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll = long long;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define MOD 1000000007
const ll INF = 1e18;
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 argc, char const *argv[]) {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> jobs(n);
  priority_queue<int> pq;
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    if (a > m)
      continue;
    jobs[m - a].pb(b); // jobs[i]:=i日目までに開始しなきゃいけない仕事
  }
  ll ans = 0;
  for (int i = m - 1; i >= 0; i--) { // 後ろからみる
    for (int b : jobs[i]) {
      pq.push(b);
    }
    if (!pq.empty()) {
      ans += pq.top();
      pq.pop();
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll = long long;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define MOD 1000000007
const ll INF = 1e18;
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 argc, char const *argv[]) {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> jobs(m);
  priority_queue<int> pq;
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    if (a > m)
      continue;
    jobs[m - a].pb(b); // jobs[i]:=i日目までに開始しなきゃいけない仕事
  }
  ll ans = 0;
  for (int i = m - 1; i >= 0; i--) { // 後ろからみる
    for (int b : jobs[i]) {
      pq.push(b);
    }
    if (!pq.empty()) {
      ans += pq.top();
      pq.pop();
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
// For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456
// a.cpp -o a.exe in cmd
#include <bits/stdc++.h>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(), c.end()
#define mp(x, y) make_pair(x, y)
#define mem(a, val) memset(a, val, sizeof(a))
#define eb emplace_back
#define pb push_back
#define f first
#define s second

using namespace std;

vector<int> v[100001];

int main() {
  std::ios::sync_with_stdio(false);
  int T;
  T = 1;
  // cin.ignore(); must be there when using getline(cin, s)
  while (T--) {
    int n, m, i, j, k;
    cin >> n >> m;
    ll ans = 0;
    pll ar[n + 1];
    for (i = 1; i <= n; ++i) {
      cin >> ar[i].s >> ar[i].f;
      v[m - ar[i].s + 1].pb(ar[i].f);
    }
    set<pii> st;
    k = 1;
    for (i = m; i >= 1; --i) {
      for (j = 0; j < v[i].size(); ++j, ++k) {
        st.insert({-1 * v[i][j], k});
      }
      if (st.size() > 0) {
        auto it = st.begin();
        ans = ans + -1 * it->f;
        st.erase(it);
      }
    }
    cout << ans << endl;
  }
  return 0;
}


Fixed submission:
// For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456
// a.cpp -o a.exe in cmd
#include <bits/stdc++.h>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(), c.end()
#define mp(x, y) make_pair(x, y)
#define mem(a, val) memset(a, val, sizeof(a))
#define eb emplace_back
#define pb push_back
#define f first
#define s second

using namespace std;

vector<int> v[100001];

int main() {
  std::ios::sync_with_stdio(false);
  int T;
  T = 1;
  // cin.ignore(); must be there when using getline(cin, s)
  while (T--) {
    int n, m, i, j, k;
    cin >> n >> m;
    ll ans = 0;
    pll ar[n + 1];
    for (i = 1; i <= n; ++i) {
      cin >> ar[i].s >> ar[i].f;
      if (m - ar[i].s + 1 <= 0)
        continue;
      v[m - ar[i].s + 1].pb(ar[i].f);
    }
    set<pii> st;
    k = 1;
    for (i = m; i >= 1; --i) {
      for (j = 0; j < v[i].size(); ++j, ++k) {
        st.insert({-1 * v[i][j], k});
      }
      if (st.size() > 0) {
        auto it = st.begin();
        ans = ans + -1 * it->f;
        st.erase(it);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0, i##__ = (n); i < i##__; ++i)
#define ALL(o) (o).begin(), (o).end()
#define PUT(a) cout << a << "\n"
#define VEC2D(v, y, x, s) vector<vector<int>> v(y, vector<int>(x, s))
// ここまでテンプレ
int main() {
  priority_queue<int> pq;
  int N, M;
  cin >> N >> M;
  VEC2D(AB, 10 ^ 5 + 1, 0, 0);

  REP(i, N) {
    int A, B;
    cin >> A >> B;
    if (A <= M)
      AB.at(A - 1).push_back(B);
  }

  REP(i, M) sort(ALL(AB[i]));

  int ans = 0;
  REP(i, M) {
    REP(j, AB[i].size()) { pq.push(AB[i][j]); }
    if (pq.size() > 0) {
      ans += pq.top();
      pq.pop();
    }
  }

  PUT(ans);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0, i##__ = (n); i < i##__; ++i)
#define ALL(o) (o).begin(), (o).end()
#define PUT(a) cout << a << "\n"
#define VEC2D(v, y, x, s) vector<vector<int>> v(y, vector<int>(x, s))
// ここまでテンプレ
int main() {
  priority_queue<int> pq;
  int N, M;
  cin >> N >> M;
  VEC2D(AB, pow(10, 5), 0, 0);

  REP(i, N) {
    int A, B;
    cin >> A >> B;
    if (A <= M)
      AB.at(A - 1).push_back(B);
  }

  REP(i, M) sort(ALL(AB[i]));

  int ans = 0;
  REP(i, M) {
    REP(j, AB[i].size()) { pq.push(AB[i][j]); }
    if (pq.size() > 0) {
      ans += pq.top();
      pq.pop();
    }
  }

  PUT(ans);
}
Problem p02948 (C++)

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;

  // Reward[n] : n日後に報酬が得られるバイトの報酬をVectorにしたやつ
  vector<int> Reward[100001];

  int a, b;
  for (int n = 0; n < N; n++) {
    cin >> a >> b;
    Reward[a].emplace_back(b);
  }

  long answer = 0;
  priority_queue<int> albeit_reward;
  for (int m = 1; m < M + 1; m++) {
    for (int r : Reward[m]) {
      albeit_reward.push(r);
    }
    answer += albeit_reward.top();
    albeit_reward.pop();
  }

  cout << answer << "\n";

  return 0;
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;

  // Reward[n] : n日後に報酬が得られるバイトの報酬をVectorにしたやつ
  vector<int> Reward[100001];

  int a, b;
  for (int n = 0; n < N; n++) {
    cin >> a >> b;
    Reward[a].emplace_back(b);
  }

  long answer = 0;
  priority_queue<int> albeit_reward;
  for (int m = 1; m < M + 1; m++) {
    for (int r : Reward[m]) {
      albeit_reward.push(r);
    }
    if (albeit_reward.size() != 0) {
      answer += albeit_reward.top();
      albeit_reward.pop();
    }
  }

  cout << answer << "\n";

  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;

  map<int, priority_queue<int>> jobs;

  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    jobs[a].push(b);
  }

  int64_t gurantee = 0;
  auto j = jobs.begin(), je = jobs.end();
  priority_queue<pair<int, int>> works;
  for (int i = 1; i <= M; i++) {
    for (; j != je && j->first <= i; j++) {
      works.push({j->second.top(), j->first});
      j->second.pop();
    }

    auto p = works.top();
    works.pop();
    gurantee += p.first;
    if (!jobs[p.second].empty()) {
      works.push({jobs[p.second].top(), p.second});
      jobs[p.second].pop();
    }
  }

  cout << gurantee << endl;
}

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

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

  map<int, priority_queue<int>> jobs;

  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    jobs[a].push(b);
  }

  int64_t gurantee = 0;
  auto j = jobs.begin(), je = jobs.end();
  priority_queue<pair<int, int>> works;
  for (int i = 1; i <= M; i++) {
    for (; j != je && j->first <= i; j++) {
      works.push({j->second.top(), j->first});
      j->second.pop();
    }

    if (!works.empty()) {
      auto p = works.top();
      works.pop();
      gurantee += p.first;
      if (!jobs[p.second].empty()) {
        works.push({jobs[p.second].top(), p.second});
        jobs[p.second].pop();
      }
    }
  }

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

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

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

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

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

  long long ans = 0;

  priority_queue<int> q;
  for (int i = m - 1; i >= 0; i--) {
    for (auto &&j : v[i]) {
      q.push(j);
    }

    if (!q.empty()) {
      ans += (long long)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;
  cin >> n >> m;

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

    if (a > m) {
      continue;
    }

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

  long long ans = 0;

  priority_queue<int> q;
  for (int i = m - 1; i >= 0; i--) {
    for (auto &&j : v[i]) {
      q.push(j);
    }

    if (!q.empty()) {
      ans += (long long)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;
typedef long long ll;

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

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

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define fo(i, w, n) for (int i = (int)w; i < (int)n; i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int, int>
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
#define prq priority_queue
#define foreach(it, c)                                                         \
  for (__typeof((c).begin()) it = c.begin(); it != c.end(); it++)
using namespace std;
inline ll read() {
  ll x = 0;
  int f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-')
      f = -f;
  for (; isdigit(c); c = getchar())
    x = x * 10 + (c - '0');
  return x * f;
}
inline void out(int x) {
  if (x >= 10)
    out(x / 10);
  putchar(x % 10 + '0');
}
int n, m, ans = 0;
pii a[101010];
prq<int> pq;
int main() {
  // freopen("a.in","r",stdin);
  // freopen("a.out","w",stdout);
  cin >> n >> m;
  fo(i, 0, n) cin >> a[i].fi >> a[i].se;
  sort(a, a + n);
  int k = 0;
  for (int i = m; i >= 0; i--) {
    while (a[k].fi <= m - i)
      pq.push(a[k++].se);
    if (!pq.empty()) {
      ans += pq.top();
      pq.pop();
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define fo(i, w, n) for (int i = (int)w; i < (int)n; i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int, int>
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
#define prq priority_queue
#define foreach(it, c)                                                         \
  for (__typeof((c).begin()) it = c.begin(); it != c.end(); it++)
using namespace std;
inline ll read() {
  ll x = 0;
  int f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-')
      f = -f;
  for (; isdigit(c); c = getchar())
    x = x * 10 + (c - '0');
  return x * f;
}
inline void out(int x) {
  if (x >= 10)
    out(x / 10);
  putchar(x % 10 + '0');
}
int n, m, ans = 0;
pii a[101010];
prq<int> pq;
int main() {
  // freopen("a.in","r",stdin);
  // freopen("a.out","w",stdout);
  cin >> n >> m;
  fo(i, 0, n) cin >> a[i].fi >> a[i].se;
  sort(a, a + n);
  int k = 0;
  for (int i = m; i >= 0; i--) {
    while (a[k].fi <= m - i && k < n)
      pq.push(a[k++].se);
    if (!pq.empty()) {
      ans += pq.top();
      pq.pop();
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02948 (C++)

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

using namespace std;
typedef long long ll;

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

  vector<vector<int>> v(m);
  REP(i, n) {
    int a, b;
    cin >> a >> b;

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

  priority_queue<int> q;
  ll ans = 0;
  for (int i = m - 1; i >= 0; i--) {
    for (int x : v[i]) {
      q.push(x);
    }
    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++)

using namespace std;
typedef long long ll;

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

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

  priority_queue<int> q;
  ll ans = 0;
  for (int i = m - 1; i >= 0; i--) {
    for (int x : v[i]) {
      q.push(x);
    }
    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>

#define MAX_A 100000

using namespace std;

int main() {

  int N, M;
  cin >> N >> M;
  vector<int> A[MAX_A];
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    A[a].emplace_back(b);
  }

  priority_queue<int> que;

  int ans = 0;
  for (int i = 1; i <= M; i++) {
    for (int id : A[i]) {
      que.push(id);
    }
    if (!que.empty()) {
      ans += que.top();
      que.pop();
    }
  }
  cout << ans << endl;
  return 0;
}

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

#define MAX_A 100001

using namespace std;

int main() {

  int N, M;
  cin >> N >> M;
  vector<int> A[MAX_A];
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    A[a].emplace_back(b);
  }

  priority_queue<int> que;

  int ans = 0;
  for (int i = 1; i <= M; i++) {
    for (int id : A[i]) {
      que.push(id);
    }
    if (!que.empty()) {
      ans += que.top();
      que.pop();
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define ll long long
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define repm(i, a, b) for (int i = (int)(a); i > (int)(b); --i)

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> jobs(10010);
  repp(i, 0, N) {
    int a, b;
    cin >> a >> b;
    jobs[a].push_back(b);
  }
  priority_queue<int> q;
  ll ans = 0;
  repp(i, 1, M + 1) {
    for (auto x : jobs[i])
      q.push(x);
    if (!q.empty())
      ans += q.top(), q.pop();
  }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define ll long long
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define repm(i, a, b) for (int i = (int)(a); i > (int)(b); --i)

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> jobs(100100);
  repp(i, 0, N) {
    int a, b;
    cin >> a >> b;
    jobs[a].push_back(b);
  }
  priority_queue<int> q;
  ll ans = 0;
  repp(i, 1, M + 1) {
    for (auto x : jobs[i])
      q.push(x);
    if (!q.empty())
      ans += q.top(), q.pop();
  }
  cout << ans << endl;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MAX = 5100000;
ll gcd(ll a, ll b) { return (b == 0) ? a : gcd(b, a % b); }

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
ll COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// 以下から
const int MAX_N = 100000;
struct Edge {
  int to;
  int id;
};

vector<vector<Edge>> g;
vector<int> ans;
const int MN = 15;
vector<int> searched(MN, 0);
vector<int> color(MN, -1);

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> days(m, vector<int>());
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    a--;
    days[a].push_back(b);
  }
  priority_queue<int> pq;
  int sum = 0;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < days[i].size(); j++) {
      pq.push(days[i][j]);
    }
    if (!pq.empty()) {
      int val = pq.top();
      pq.pop();
      sum += val;
    }
  }

  cout << sum << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MAX = 5100000;
ll gcd(ll a, ll b) { return (b == 0) ? a : gcd(b, a % b); }

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
ll COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// 以下から
const int MAX_N = 100000;
struct Edge {
  int to;
  int id;
};

vector<vector<Edge>> g;
vector<int> ans;
const int MN = 15;
vector<int> searched(MN, 0);
vector<int> color(MN, -1);

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> days(100000);
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    a--;
    days[a].push_back(b);
  }
  priority_queue<int> pq;
  int sum = 0;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < days[i].size(); j++) {
      pq.push(days[i][j]);
    }
    if (!pq.empty()) {
      int val = pq.top();
      pq.pop();
      sum += val;
    }
  }

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

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

int main() {
  int N, M;
  cin >> N >> M;
  int a[N], b[N];
  vector<P> ab;
  for (int i = 0; i < N; i++) {
    cin >> a[i] >> b[i];
    ab.push_back(P(a[i], b[i]));
  }

  sort(ab.begin(), ab.end());
  int num = 0;
  int ans = 0;
  priority_queue<P> que;

  for (int A = 1; A <= M; A++) {
    while (ab[num].first <= A) {
      que.push(P(ab[num].second, ab[num].first));
      num++;
    }
    if (!que.empty()) {
      P p = que.top();
      ans += p.first;
      que.pop();
    }
  }

  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

int main() {
  int N, M;
  cin >> N >> M;
  int a[N], b[N];
  vector<P> ab;
  for (int i = 0; i < N; i++) {
    cin >> a[i] >> b[i];
    ab.push_back(P(a[i], b[i]));
  }

  sort(ab.begin(), ab.end());
  int num = 0;
  int ans = 0;
  priority_queue<P> que;

  for (int A = 1; A <= M; A++) {
    while (ab[num].first <= A && num < N) {
      que.push(P(ab[num].second, ab[num].first));
      num++;
    }
    if (!que.empty()) {
      P p = que.top();
      ans += p.first;
      que.pop();
    }
  }

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

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

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> ev[10010];
  for (int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    if (M - x >= 0)
      ev[M - x].emplace_back(y);
  }
  long long ret = 0;
  priority_queue<int> que;
  for (int i = M; i >= 0; i--) {
    for (auto &p : ev[i])
      que.emplace(p);
    if (que.size()) {
      ret += que.top();
      que.pop();
    }
  }
  cout << ret << endl;
}


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

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> ev[100100];
  for (int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    if (M - x >= 0)
      ev[M - x].emplace_back(y);
  }
  long long ret = 0;
  priority_queue<int> que;
  for (int i = M; i >= 0; i--) {
    for (auto &p : ev[i])
      que.emplace(p);
    if (que.size()) {
      ret += que.top();
      que.pop();
    }
  }
  cout << ret << endl;
}
Problem p02948 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> AB(N);
  for (auto &ab : AB)
    cin >> ab.first >> ab.second;
  sort(AB.begin(), AB.end(),
       [](const pair<int, int> &_a, const pair<int, int> &_b) {
         return _a.second > _b.second;
       });
  int ans = 0;
  vector<int> V(M);
  for (int i = 0; i < M; i++) {
    V[i] = i + 1;
  }
  set<int> S(V.begin(), V.end());
  for (const auto &ab : AB) {
    if (S.empty())
      break;
    auto it = lower_bound(S.begin(), S.end(), ab.first);
    if (it == S.end())
      continue;
    S.erase(*it);
    ans += ab.second;
  }
  printf("%d\n", ans);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> AB(N);
  for (auto &ab : AB)
    cin >> ab.first >> ab.second;
  sort(AB.begin(), AB.end());
  priority_queue<int> Q;
  int ans = 0, j = 0;
  for (int i = 1; i <= M; i++) {
    while (j < N && AB[j].first == i) {
      Q.push(AB[j].second);
      j++;
    }
    if (!Q.empty()) {
      ans += Q.top();
      Q.pop();
    }
  }
  printf("%d\n", ans);
  return 0;
}
Problem p02948 (C++)

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

#if defined(DEBUG)

#include <sys/fcntl.h>
#include <unistd.h>
#define DLOG(...) cerr << dbgFormat(__VA_ARGS__) << endl
#define DCALL(func, ...) func(__VA_ARGS__)

template <class... Args> string dbgFormat(const char *fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#else // defined(DEBUG)

#define DLOG(...)
#define DCALL(func, ...)

#endif // defined(DEBUG)

int main(int argc, char *argv[]) {
#if defined(DEBUG)
  // GDB on Cygwin ignores redirection at run command.
  if (argc == 2)
    dup2(open(argv[1], 0), 0);
#else
  // For performance.  We should not use C-style stdio functions
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#endif
  cout << setprecision(20);

  int N, M;
  cin >> N >> M;
  vector<int> A(N), B(N);
  for (int i = 0; i < N; i++)
    cin >> A.at(i) >> B.at(i);
  vector<int> ord(N);
  for (int i = 0; i < N; i++)
    ord.at(i) = i;
  sort(ord.begin(), ord.end(), [A](int x, int y) { return A.at(x) < A.at(y); });
  // priority_queue<int, vector<int>, greater<int>> que;
  priority_queue<int> que;
  int i = 0;
  int ans = 0;
  for (int d = 1; d <= M; d++) {
    while (i < N && A.at(ord.at(i)) <= d) {
      que.push(B.at(ord.at(i)));
      i++;
    }
    if (!que.empty()) {
      ans += que.top();
      que.pop();
    }
  }
  cout << ans << endl;

  return 0;
}


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

#if defined(DEBUG)

#include <sys/fcntl.h>
#include <unistd.h>
#define DLOG(...) cerr << dbgFormat(__VA_ARGS__) << endl
#define DCALL(func, ...) func(__VA_ARGS__)

template <class... Args> string dbgFormat(const char *fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#else // defined(DEBUG)

#define DLOG(...)
#define DCALL(func, ...)

#endif // defined(DEBUG)

int main(int argc, char *argv[]) {
#if defined(DEBUG)
  // GDB on Cygwin ignores redirection at run command.
  if (argc == 2)
    dup2(open(argv[1], 0), 0);
#else
  // For performance.  We should not use C-style stdio functions
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#endif
  cout << setprecision(20);

  int N, M;
  cin >> N >> M;
  vector<int> A(N), B(N);
  for (int i = 0; i < N; i++)
    cin >> A.at(i) >> B.at(i);
  vector<int> ord(N);
  for (int i = 0; i < N; i++)
    ord.at(i) = i;
  sort(ord.begin(), ord.end(), [&](int x, int y) { return A.at(x) < A.at(y); });
  priority_queue<int> que;
  int i = 0;
  int ans = 0;
  for (int d = 1; d <= M; d++) {
    while (i < N && A.at(ord.at(i)) <= d) {
      que.push(B.at(ord.at(i)));
      i++;
    }
    if (!que.empty()) {
      ans += que.top();
      que.pop();
    }
  }
  cout << ans << endl;

  return 0;
}
Problem p02948 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long
#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define lpri(n) printf("%lld", n)
#define pri(n) printf("%d", n)
#define pln() printf("\n")
#define priln(n) printf("%d\n", n)
#define lpriln(n) printf("%lld\n", n)
#define rep(i, init, n) for (int i = init; i < n; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
using namespace std;
const ll mod = 1e9 + 7;
const int N = 1e5 + 4;
typedef pair<int, int> pii;
int main() {
  int n, m;
  scn(n);
  scn(m);
  vector<pii> v;
  rep(i, 0, n) {
    pii p;
    scn(p.S);
    scn(p.F);
    v.pb(p);
  }
  set<int> s;
  rep(i, 0, m + 1) s.insert(i);
  sort(v.rbegin(), v.rend());
  ll total = 0;
  for (auto it : v) {
    if (it.S > m)
      continue;
    if (s.find(m - it.S) != s.end()) {
      s.erase(m - it.S);
      total += (ll)it.F;
    } else {
      auto iter = upper_bound(s.begin(), s.end(), m - it.S);
      if (iter == s.begin())
        continue;
      iter--;
      s.erase(*iter);
      total += (ll)it.F;
    }
  }
  lpri(total);
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define lpri(n) printf("%lld", n)
#define pri(n) printf("%d", n)
#define pln() printf("\n")
#define priln(n) printf("%d\n", n)
#define lpriln(n) printf("%lld\n", n)
#define rep(i, init, n) for (int i = init; i < n; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
using namespace std;
const ll mod = 1e9 + 7;
const int N = 1e5 + 4;
typedef pair<int, int> pii;
int main() {
  int n, m;
  scn(n);
  scn(m);
  vector<pii> v;
  rep(i, 0, n) {
    pii p;
    scn(p.S);
    scn(p.F);
    v.pb(p);
  }
  set<int> s;
  rep(i, 0, m + 1) s.insert(i);
  sort(v.rbegin(), v.rend());
  ll total = 0;
  for (auto it : v) {
    if (it.S > m)
      continue;
    if (s.find(m - it.S) != s.end()) {
      s.erase(m - it.S);
      total += (ll)it.F;
    } else {
      auto iter = s.upper_bound(m - it.S);
      if (iter == s.begin())
        continue;
      iter--;
      s.erase(*iter);
      total += (ll)it.F;
    }
  }
  lpri(total);
}
Problem p02948 (C++)

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

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

  int ans = 0;
  priority_queue<int> pq;
  for (int i = 1; i <= M; i++) {
    for (auto e : v[i])
      pq.push(e);
    if (!pq.empty()) {
      ans += pq.top();
      pq.pop();
    }
  }

  cout << ans << endl;
}

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

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

  int ans = 0;
  priority_queue<int> pq;
  for (int i = 1; i <= M; i++) {
    for (auto e : v[i])
      pq.push(e);
    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 (ll i = 0; i < n; ++i)
#define all_map(pos, mp) for (ll pos = mp.begin(); pos != mp.end(); pos - ++)
#define ALL(a) (a).begin(), (a).end()

using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

const ll MOD = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

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

  // reward[i] : i+1日後にもらえる報酬のベクトル
  vector<vector<ll>> reward(m);
  rep(i, n) {
    ll a, b;
    cin >> a >> b;
    reward[a - 1].push_back(b);
  }

  // 未来から逆算，Mまでにもらえる最大報酬のバイトをする
  priority_queue<ll> que;
  ll ans = 0;
  rep(i, m) {
    for (ll r_i : reward[i])
      que.push(r_i);

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

  cout << ans << endl;
}

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

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define all_map(pos, mp) for (ll pos = mp.begin(); pos != mp.end(); pos - ++)
#define ALL(a) (a).begin(), (a).end()

using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

const ll MOD = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

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

  // reward[i] : i+1日後にもらえる報酬のベクトル
  vector<vector<ll>> reward(100010);
  rep(i, n) {
    ll a, b;
    cin >> a >> b;
    reward[a - 1].push_back(b);
  }

  // 未来から逆算，Mまでにもらえる最大報酬のバイトをする
  priority_queue<ll> que;
  ll ans = 0;
  rep(i, m) {
    for (ll r_i : reward[i])
      que.push(r_i);

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

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MAX = 5100000;
ll gcd(ll a, ll b) { return (b == 0) ? a : gcd(b, a % b); }

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
ll COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// 以下から
const int MAX_N = 100000;
struct Edge {
  int to;
  int id;
};

vector<vector<Edge>> g;
vector<int> ans;

void dfs(int v, int c = -1, int p = -1) {
  int k = 1;
  rep(i, g[v].size()) {
    int u = g[v][i].to, ei = g[v][i].id;
    if (u == p)
      continue;
    if (k == c)
      ++k;
    ans[ei] = k;
    ++k;
    dfs(u, ans[ei], v);
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> v(m + 5);
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    v[a].push_back(b);
  }

  int ans = 0;
  priority_queue<int> pq;
  for (int i = 1; i <= m; i++) {
    rep(j, v[i].size()) { pq.push(v[i][j]); }
    if (!pq.empty()) {
      ans += pq.top();
      pq.pop();
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MAX = 5100000;
ll gcd(ll a, ll b) { return (b == 0) ? a : gcd(b, a % b); }

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
ll COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// 以下から
const int MAX_N = 100000;
struct Edge {
  int to;
  int id;
};

vector<vector<Edge>> g;
vector<int> ans;

void dfs(int v, int c = -1, int p = -1) {
  int k = 1;
  rep(i, g[v].size()) {
    int u = g[v][i].to, ei = g[v][i].id;
    if (u == p)
      continue;
    if (k == c)
      ++k;
    ans[ei] = k;
    ++k;
    dfs(u, ans[ei], v);
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> v(100005);
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    v[a].push_back(b);
  }

  int ans = 0;
  priority_queue<int> pq;
  for (int i = 1; i <= m; i++) {
    rep(j, v[i].size()) { pq.push(v[i][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 REP(a, b, c) for (register int a = b, _n = c; a <= _n; ++a)
#define DREP(a, b, c) for (register int a = b, _n = c; a >= _n; --a)
#define FOR(a, b, c) for (register int a = b, _n = c; a < _n; ++a)
#define DFOR(a, b, c) for (register int a = b, _n = c; a > _n; --a)
#define EREP(a, b) for (register int a = first[b]; a; a = edge[a].nxt)

const int SIZE = 100005;

int n, m;

int ans;
struct Node {
  int a, b;
} x[SIZE];
struct cmp {
  bool operator()(const Node &x1, const Node &x2) const { return x1.b > x2.b; }
};

int fa[100005];
int Find(int x) {
  if (x == fa[x])
    return x;
  return fa[x] = Find(fa[x]);
}

void _main() {
  scanf("%d%d", &n, &m);

  REP(i, 1, m) fa[i] = i;

  REP(i, 1, n) { scanf("%d%d", &x[i].a, &x[i].b); }
  sort(x + 1, x + n + 1, cmp());

  REP(i, 1, n) {
    int fx = Find(m - x[i].a + 1);
    if (fx) {
      ans += x[i].b;
      fa[fx] = Find(fx - 1);
    }
  }

  printf("%d\n", ans);
}

int main() {
#ifdef LOCAL
  freopen("in.txt", "r", stdin);
#endif
  _main();
  return 0;
}


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

using namespace std;

#define REP(a, b, c) for (register int a = b, _n = c; a <= _n; ++a)
#define DREP(a, b, c) for (register int a = b, _n = c; a >= _n; --a)
#define FOR(a, b, c) for (register int a = b, _n = c; a < _n; ++a)
#define DFOR(a, b, c) for (register int a = b, _n = c; a > _n; --a)
#define EREP(a, b) for (register int a = first[b]; a; a = edge[a].nxt)

const int SIZE = 100005;

int n, m;

int ans;
struct Node {
  int a, b;
} x[SIZE];
struct cmp {
  bool operator()(const Node &x1, const Node &x2) const { return x1.b > x2.b; }
};

int fa[100005];
int Find(int x) {
  if (x == fa[x])
    return x;
  return fa[x] = Find(fa[x]);
}

void _main() {
  scanf("%d%d", &n, &m);

  REP(i, 1, m) fa[i] = i;

  REP(i, 1, n) { scanf("%d%d", &x[i].a, &x[i].b); }
  sort(x + 1, x + n + 1, cmp());

  REP(i, 1, n) if (m >= x[i].a) {
    int fx = Find(m - x[i].a + 1);
    if (fx) {
      ans += x[i].b;
      fa[fx] = Find(fx - 1);
    }
  }

  printf("%d\n", ans);
}

int main() {
#ifdef LOCAL
  freopen("in.txt", "r", stdin);
#endif
  _main();
  return 0;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> k(m, vector<int>(1, 0));
  int ans = 0;
  priority_queue<int, vector<int>, less<int>> q;
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    k[a - 1].push_back(b);
  }
  rep(i, m) {
    rep(j, k[i].size()) {
      int w = k[i][j];
      q.push(w);
    }
    if (q.size() >= 1) {
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> k(m, vector<int>(1, 0));
  int ans = 0;
  priority_queue<int, vector<int>, less<int>> q;
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    if (a > m)
      continue;
    k[a - 1].push_back(b);
  }
  rep(i, m) {
    rep(j, k[i].size()) {
      int w = k[i][j];
      q.push(w);
    }
    if (q.size() >= 1) {
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << endl;
}
Problem p02948 (C++)

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

using namespace std;

vector<int> ve[12000];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  int x, y;
  for (int i = 0; i < n; i++) {
    cin >> x >> y;
    if (x > k)
      continue;
    int tt = k - x + 1;
    ve[tt].push_back(y);
  }

  priority_queue<int> q;
  int ans = 0;
  for (int i = k; i >= 1; i--) {
    for (int j = 0; j < ve[i].size(); j++)
      q.push(ve[i][j]);
    if (!q.empty()) {
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << "\n";

  return 0;
}

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

using namespace std;

vector<int> ve[120000];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  int x, y;
  for (int i = 0; i < n; i++) {
    cin >> x >> y;
    if (x > k)
      continue;
    int tt = k - x + 1;
    ve[tt].push_back(y);
  }

  priority_queue<int> q;
  int ans = 0;
  for (int i = k; i >= 1; i--) {
    for (int j = 0; j < ve[i].size(); j++)
      q.push(ve[i][j]);
    if (!q.empty()) {
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << "\n";

  return 0;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rrep(i, n) for (ll i##_len = (n), i = i##_len - 1; i >= 0; --i)
#define repi(i, a, b) for (ll i = ll(a); i < ll(b); ++i)
#define printd(val) std::cout << #val " = " << val << "\n";
#include <bits/stdc++.h>
using ll = long long;
using pii = std::pair<int, int>;
using namespace std;
template <class T> T chmin(T a, T b) {
  if (a > b) {
    a ^= b;
    b ^= a;
    a ^= b;
    return 1;
  }
  return 0;
}
template <class T> T chmax(T b, T a) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
    return 1;
  }
  return 0;
}

int n, m;
vector<vector<ll>> v;
priority_queue<ll> qt;

void input() {
  cin >> n >> m;
  int a, b;
  v.resize(100010);
  rep(i, n) {
    cin >> a >> b;
    v.at(a).push_back(b);
  }
}
void src() {
  ll sum = 0;
  rep(day, m) {
    if (!v.at(day + 1).empty()) {
      for (auto i : v.at(day + 1)) {
        qt.push(i);
      }
    }
    sum += qt.top();
    qt.pop();
  }
  cout << sum;
  return;
}

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
  //   ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
  input();
  src();
  return 0;
}

Fixed submission:
#define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rrep(i, n) for (ll i##_len = (n), i = i##_len - 1; i >= 0; --i)
#define repi(i, a, b) for (ll i = ll(a); i < ll(b); ++i)
#define printd(val) std::cout << #val " = " << val << "\n";
#include <bits/stdc++.h>
using ll = long long;
using pii = std::pair<int, int>;
using namespace std;
template <class T> T chmin(T a, T b) {
  if (a > b) {
    a ^= b;
    b ^= a;
    a ^= b;
    return 1;
  }
  return 0;
}
template <class T> T chmax(T b, T a) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
    return 1;
  }
  return 0;
}

int n, m;
vector<vector<ll>> v;
priority_queue<ll> qt;

void input() {
  cin >> n >> m;
  int a, b;
  v.resize(100010);
  rep(i, n) {
    cin >> a >> b;
    v.at(a).push_back(b);
  }
}
void src() {
  ll sum = 0;
  rep(day, m) {
    if (!v.at(day + 1).empty()) {
      for (auto i : v.at(day + 1)) {
        qt.push(i);
      }
    }
    if (!qt.empty()) {
      sum += qt.top();
      qt.pop();
    }
  }
  cout << sum;
  return;
}

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
  //   ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
  input();
  src();
  return 0;
}