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

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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<string> s;
  string t;
  for (int i = 0; i < N; i++) {
    cin >> t;
    s.push_back(t);
  }

  for (int i = 0; i < N; i++) {
    std::sort(s[i].begin(), s[i].end());
  }

  std::sort(s.begin(), s.end());

  long long count = 0;
  long long conv = 1;
  for (int i = 0; i < N; i++) {
    if (s[i] == s[i + 1]) {
      conv++;
    } else {
      if (conv >= 2) {
        count += (conv * (conv - 1) / 2);
      }
      conv = 1;
    }
  }
  cout << count << endl;
}

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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<string> s;
  string t;
  for (int i = 0; i < N; i++) {
    cin >> t;
    s.push_back(t);
  }

  s.push_back("{{{{{{{{{{");
  for (int i = 0; i < N; i++) {
    std::sort(s[i].begin(), s[i].end());
  }

  std::sort(s.begin(), s.end());

  long long count = 0;
  long long conv = 1;
  for (int i = 0; i < N; i++) {
    if (s[i] == s[i + 1]) {
      conv++;
    } else {
      if (conv >= 2) {
        count += (conv * (conv - 1) / 2);
      }
      conv = 1;
    }
  }
  cout << count << endl;
}
Problem p02947 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <string>

int main(void) {
  int n;
  std::cin >> n;

  std::map<std::string, int> mp;

  for (int i = 0; i < n; i++) {
    std::string s;
    std::cin >> s;
    std::sort(s.begin(), s.end());
    mp.at(s)++;
  }

  long long ans = 0;
  for (auto &p : mp) {
    int temp = p.second;
    ans += (long long)temp * (temp - 1) / 2;
  }
  std::cout << ans << std::endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <string>

int main(void) {
  int n;
  std::cin >> n;

  std::map<std::string, int> mp;

  for (int i = 0; i < n; i++) {
    std::string s;
    std::cin >> s;
    std::sort(s.begin(), s.end());
    mp[s]++;
  }

  long long ans = 0;
  for (auto &p : mp) {
    int temp = p.second;
    ans += (long long)temp * (temp - 1) / 2;
  }
  std::cout << ans << std::endl;
  return 0;
}
Problem p02948 (C++)

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

using ll = long long;
const int INF = 1001001001;

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

int main() {
  ll n, m;
  cin >> n >> m;
  vector<vector<ll>> day(m + 1);
  priority_queue<ll> today;

  rep(i, n) {
    ll a, b;
    cin >> a >> b;
    day[m - a + 1].push_back(b);
  }

  ll result = 0;
  for (ll i = m; i >= 1; i--) {
    if (!day[i].empty()) {
      for (auto x : day[i]) {
        today.push(x);
      }
    }
    if (!today.empty()) {
      result += today.top();
      today.pop();
    }
  }

  cout << result << endl;
}


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

using ll = long long;
const int INF = 1001001001;

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

int main() {
  ll n, m;
  cin >> n >> m;
  vector<vector<ll>> day(m + 1);
  priority_queue<ll> today;

  rep(i, n) {
    ll a, b;
    cin >> a >> b;
    if (m - a + 1 < 1)
      continue;
    day[m - a + 1].push_back(b);
  }

  ll result = 0;
  for (ll i = m; i >= 1; i--) {
    if (!day[i].empty()) {
      for (auto x : day[i]) {
        today.push(x);
      }
    }
    if (!today.empty()) {
      result += today.top();
      today.pop();
    }
  }

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>
using namespace std;

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

const int mod = 1000000007;

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

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

  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>
using namespace std;

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

const int mod = 1000000007;

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

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

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
int main(void) {
  int n, m;
  cin >> n >> m;
  vector<int> p[m + 1];
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    p[a].push_back(b);
  }
  // rep(i,n) cout << p[i].second << " " << p[i].first << endl;
  priority_queue<int> que;
  ll ans = 0;
  for (int i = 1; i <= m; i++) {
    for (int j = 0; j < p[i].size(); j++) {
      que.push(p[i][j]);
    }
    if (!que.empty()) {
      ans += que.top();
      que.pop();
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
int main(void) {
  int n, m;
  cin >> n >> m;
  vector<int> p[100005];
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    p[a].push_back(b);
  }
  // rep(i,n) cout << p[i].second << " " << p[i].first << endl;
  priority_queue<int> que;
  ll ans = 0;
  for (int i = 1; i <= m; i++) {
    for (int j = 0; j < p[i].size(); j++) {
      que.push(p[i][j]);
    }
    if (!que.empty()) {
      ans += que.top();
      que.pop();
    }
  }
  cout << ans << endl;
}
Problem p02948 (C++)

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

void solve() {
  priority_queue<int> q;
  int n, m;
  cin >> n >> m;
  vector<vector<int>> v(m + 1);
  int a, b;
  rep(i, n) {
    cin >> a >> b;
    v[a].push_back(b);
  }
  ll ans = 0;
  for (int i = 0; i <= m; ++i) {
    if (v[i].empty()) {
      q.push(0);
    } else {
      for (int j : v[i])
        q.push(j);
    }
    ans += q.top();
    q.pop();
  }

  cout << ans << endl;
}

int main() {
  solve();
  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;

void solve() {
  priority_queue<int> q;
  int n, m;
  cin >> n >> m;
  vector<vector<int>> v(m + 1);
  int a, b;
  rep(i, n) {
    cin >> a >> b;
    if (a < m + 1) {
      v[a].push_back(b);
    }
  }
  ll ans = 0;
  for (int i = 0; i <= m; ++i) {
    if (v[i].empty()) {
      q.push(0);
    } else {
      for (int j : v[i])
        q.push(j);
    }
    ans += q.top();
    q.pop();
  }

  cout << ans << endl;
}

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

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> ab(N, vector<int>(2));
  for (int i = 0; i < N; i++) {
    cin >> ab[i][0] >> ab[i][1];
  }
  sort(ab.begin(), ab.end());
  priority_queue<int> pq;
  int s = 0;
  int sum = 0;
  for (int i = 1; i < M + 1; i++) {
    for (int j = s; j < N; j++) {
      if (ab[j][0] == i) {
        pq.push(ab[j][1]);
        s++;
      }
    }
    if (!pq.empty()) {
      sum += pq.top();
      pq.pop();
    }
  }
  cout << sum << endl;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> ab(N, vector<int>(2));
  for (int i = 0; i < N; i++) {
    cin >> ab[i][0] >> ab[i][1];
  }
  sort(ab.begin(), ab.end());
  priority_queue<int> pq;
  int s = 0;
  int sum = 0;
  for (int i = 1; i < M + 1; i++) {
    for (int j = s; j < N; j++) {
      if (ab[j][0] == i) {
        pq.push(ab[j][1]);
        s++;
      } else {
        break;
      }
    }
    if (!pq.empty()) {
      sum += pq.top();
      pq.pop();
    }
  }
  cout << sum << endl;
}
Problem p02948 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define INF 100000000000
#define MAX 200001
#define MOD 1000000007
ll fac[MAX], finv[MAX], inv[MAX];
const int MX = 1000005;

int main() {
  int N, M;
  cin >> N >> M;
  vector<P> AB(N);
  priority_queue<int> que;
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    AB[i] = {a, b};
  }
  sort(AB.begin(), AB.end());
  int idx = 0;
  int day = 1;
  int ans = 0;
  while (day != M + 1) {
    int cnt = 0;
    for (int i = idx; i < N; i++) {
      if (AB[i].first <= day) {
        cnt++;
        que.push(AB[i].second);
      }
    }
    idx += cnt;
    day++;
    if (!que.empty()) {
      ans += que.top();
      que.pop();
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define INF 100000000000
#define MAX 200001
#define MOD 1000000007
ll fac[MAX], finv[MAX], inv[MAX];
const int MX = 1000005;

int main() {
  int N, M;
  cin >> N >> M;
  vector<P> AB(N);
  priority_queue<int> que;
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    AB[i] = {a, b};
  }
  sort(AB.begin(), AB.end());
  int idx = 0;
  int day = 1;
  int ans = 0;
  while (day != M + 1) {
    int cnt = 0;
    for (int i = idx; i < N; i++) {
      if (AB[i].first <= day) {
        cnt++;
        que.push(AB[i].second);
      } else
        break;
    }
    idx += cnt;
    day++;
    if (!que.empty()) {
      ans += que.top();
      que.pop();
    }
  }
  cout << ans << endl;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long int ll;
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; }
long long LCM(long long a, long long b) { return a / GCD(a, b) * b; }

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

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long int ll;
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; }
long long LCM(long long a, long long b) { return a / GCD(a, b) * b; }

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> money(100001);
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    if (a <= m)
      money[a].push_back(b);
  }
  int ans = 0;
  priority_queue<int> q;
  for (int i = 1; i <= m; i++) {
    for (int j = 0; j < money[i].size(); j++)
      q.push(money[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>
#define int int64_t
using namespace std;

signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  priority_queue<int> q;
  vector<vector<int>> v(m + 1);
  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    v[a].emplace_back(b);
  }
  int ret = 0;
  for (int i = 1; i <= m; ++i) {
    for (int k : v[i]) {
      q.emplace(k);
    }
    if (!q.empty()) {
      ret += q.top();
      q.pop();
    }
  }
  cout << ret;
  return 0;
}


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

signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  priority_queue<int> q;
  vector<vector<int>> v(m + 1);
  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    if (a <= m)
      v[a].emplace_back(b);
  }
  int ret = 0;
  for (int i = 1; i <= m; ++i) {
    for (int k : v[i]) {
      q.emplace(k);
    }
    if (!q.empty()) {
      ret += q.top();
      q.pop();
    }
  }
  cout << ret;
  return 0;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define M 100005
struct D {
  int x, y;
  bool operator<(D a) const { return y == a.y ? x < a.x : y > a.y; }
} A[M];
int n, m, F[M];
int gf(int x) { return x == F[x] ? x : F[x] = gf(F[x]); }
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i)
    scanf("%d%d", &A[i].x, &A[i].y);
  for (int i = 1; i <= m; ++i)
    F[i] = i;
  sort(A + 1, A + n + 1);
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    int p = m - A[i].x + 1;
    int fa = gf(p);
    if (fa)
      ans += A[i].y, F[fa] = fa - 1;
  }
  printf("%lld", ans);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define M 100005
struct D {
  int x, y;
  bool operator<(D a) const { return y == a.y ? x < a.x : y > a.y; }
} A[M];
int n, m, F[M];
int gf(int x) { return x == F[x] ? x : F[x] = gf(F[x]); }
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i)
    scanf("%d%d", &A[i].x, &A[i].y);
  for (int i = 1; i <= m; ++i)
    F[i] = i;
  sort(A + 1, A + n + 1);
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    int p = m - A[i].x + 1;
    if (p <= 0)
      continue;
    int fa = gf(p);
    if (fa)
      ans += A[i].y, F[fa] = fa - 1;
  }
  printf("%lld", ans);
  return 0;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<ll, ll>> a(max(n, m) + 10, {1000000, 0});
  for (int i = 0; i < n; i++) {
    cin >> a[i].first >> a[i].second;
  }
  auto compare = [](auto const &l, auto const &r) {
    if (l.first != r.first) {
      return l.first < r.first;
    } else if (l.second != r.second) {
      return l.second > r.second;
    } else {
      return true;
    }
  };
  sort(a.begin(), a.end(), compare);

  auto compare2 = [](auto l, auto r) { return l.second < r.second; };
  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, decltype(compare2)> que{
      compare2};
  ll ans = 0;
  auto itr = a.begin();
  for (int i = 0; i < m; i++) {
    while (itr != a.end() && (*itr).first < i + 2) {
      que.push(*itr);
      itr++;
    }
    if (que.empty()) {
      continue;
    }
    ans += que.top().second;
    que.pop();
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<ll, ll>> a(max(n, m) + 10, {1000000, 0});
  for (int i = 0; i < n; i++) {
    cin >> a[i].first >> a[i].second;
  }
  auto compare = [](auto const &l, auto const &r) {
    if (l.first != r.first) {
      return l.first < r.first;
    } else if (l.second != r.second) {
      return l.second > r.second;
    } else {
      return false;
    }
  };
  sort(a.begin(), a.end(), compare);

  auto compare2 = [](auto l, auto r) { return l.second < r.second; };
  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, decltype(compare2)> que{
      compare2};
  ll ans = 0;
  auto itr = a.begin();
  for (int i = 0; i < m; i++) {
    while (itr != a.end() && (*itr).first < i + 2) {
      que.push(*itr);
      itr++;
    }
    if (que.empty()) {
      continue;
    }
    ans += que.top().second;
    que.pop();
  }
  cout << ans << endl;
  return 0;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ld double
#define ull unsigned long long
#define ll long long
#define pii pair<int, int>
#define iiii pair<int, pii>
#define mp make_pair
#define INF 1000000000
#define MOD 1000000007
#define rep(i, x) for (int(i) = 0; (i) < (x); (i)++)
inline int getint() {
  int x = 0, p = 1;
  char c = getchar();
  while (c <= 32)
    c = getchar();
  if (c == 45)
    p = -p, c = getchar();
  while (c > 32)
    x = x * 10 + c - 48, c = getchar();
  return x * p;
}
using namespace std;
// ruogu
const int N = 1e5 + 5;
int n, m, a[N];
vector<int> v[N];
priority_queue<int> pq;
//
int main() {
  n = getint();
  m = getint() + 1;
  rep(i, n) {
    int x = getint();
    a[i] = getint();
    v[m - x].push_back(a[i]);
  }
  int res = 0;
  for (int i = m; i >= 1; i--) {
    rep(j, v[i].size()) pq.push(v[i][j]);
    if (pq.size()) {
      res += pq.top();
      pq.pop();
    }
  }
  cout << res << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define ld double
#define ull unsigned long long
#define ll long long
#define pii pair<int, int>
#define iiii pair<int, pii>
#define mp make_pair
#define INF 1000000000
#define MOD 1000000007
#define rep(i, x) for (int(i) = 0; (i) < (x); (i)++)
inline int getint() {
  int x = 0, p = 1;
  char c = getchar();
  while (c <= 32)
    c = getchar();
  if (c == 45)
    p = -p, c = getchar();
  while (c > 32)
    x = x * 10 + c - 48, c = getchar();
  return x * p;
}
using namespace std;
// ruogu
const int N = 1e5 + 5;
int n, m, a[N];
vector<int> v[N];
priority_queue<int> pq;
//
int main() {
  n = getint();
  m = getint() + 1;
  rep(i, n) {
    int x = getint();
    a[i] = getint();
    if (m - x > 0)
      v[m - x].push_back(a[i]);
  }
  int res = 0;
  for (int i = m; i >= 1; i--) {
    rep(j, v[i].size()) pq.push(v[i][j]);
    if (pq.size()) {
      res += pq.top();
      pq.pop();
    }
  }
  cout << res << endl;
  return 0;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n, 0), b(n, 0);
  map<int, int> mp;
  priority_queue<pair<int, int>> p;

  priority_queue<int> pq;
  rep(i, n) {
    cin >> a[i] >> b[i];
    if (a[i] <= m) {
      p.push({-a[i], b[i]});
    }
  }

  ll ans = 0;
  for (int i = 1; i <= m; i++) {
    while ((-p.top().first <= i) && (!p.empty())) {
      pq.push(p.top().second);
      p.pop();
    }
    if (!pq.empty()) {
      ans += pq.top();
      pq.pop();
    }
  }
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n, 0), b(n, 0);
  map<int, int> mp;
  priority_queue<pair<int, int>> p;

  priority_queue<int> pq;
  rep(i, n) {
    cin >> a[i] >> b[i];
    if (a[i] <= m) {
      p.push({-a[i], b[i]});
    }
  }

  ll ans = 0;
  for (int i = 1; i <= m; i++) {
    while ((!p.empty()) && (-p.top().first <= i)) {
      pq.push(p.top().second);
      p.pop();
    }
    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 ms(x, n) memset(x, n, sizeof(x));
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define rep1(i, n) for (int i = 1; i <= (int)n; ++i)
#define pb push_back
#define PI acos(-1.0)
#define LONG_LONG_MAX 9223372036854775807
#define LONG_LONG_MIN -9223372036854775808
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;

const int maxn = 1e5 + 10;
int n, m, a, b;
vector<int> vec[maxn];
multiset<int> mts;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  rep(i, n) {
    cin >> a >> b;
    vec[m - a].pb(b);
  }
  ll ans = 0;
  for (int i = m; i >= 0; --i) {
    while (!vec[i].empty()) {
      mts.insert(*prev(vec[i].end()));
      vec[i].pop_back();
    }
    if (!mts.empty()) {
      ans += *prev(mts.end());
      mts.erase(prev(mts.end()));
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define ms(x, n) memset(x, n, sizeof(x));
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define rep1(i, n) for (int i = 1; i <= (int)n; ++i)
#define pb push_back
#define PI acos(-1.0)
#define LONG_LONG_MAX 9223372036854775807
#define LONG_LONG_MIN -9223372036854775808
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;

const int maxn = 1e5 + 10;
int n, m, a, b;
vector<int> vec[maxn];
multiset<int> mts;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  rep(i, n) {
    cin >> a >> b;
    if (m - a >= 0)
      vec[m - a].pb(b);
  }
  ll ans = 0;
  for (int i = m; i >= 0; --i) {
    while (!vec[i].empty()) {
      mts.insert(*prev(vec[i].end()));
      vec[i].pop_back();
    }
    if (!mts.empty()) {
      ans += *prev(mts.end());
      mts.erase(prev(mts.end()));
    }
  }
  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 REP2(i, x, n) for (int i = x; i < (n); i++)
#define ALL(n) begin(n), end(n)
struct cww {
  cww() {
    ios::sync_with_stdio(false);
    cin.tie(0);
  }
} star;
const long long INF = numeric_limits<long long>::max();
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>> Q(10100);
  REP(i, N) {
    int A, B;
    cin >> A >> B;
    Q[A].push_back(B);
  }
  int ans = 0;
  priority_queue<int> pq;
  for (int i = 1; i <= M; i++) {
    REP(j, Q[i].size()) { pq.push(Q[i][j]); }
    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 REP2(i, x, n) for (int i = x; i < (n); i++)
#define ALL(n) begin(n), end(n)
struct cww {
  cww() {
    ios::sync_with_stdio(false);
    cin.tie(0);
  }
} star;
const long long INF = numeric_limits<long long>::max();
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>> Q(100100);
  REP(i, N) {
    int A, B;
    cin >> A >> B;
    Q[A].push_back(B);
  }
  int ans = 0;
  priority_queue<int> pq;
  for (int i = 1; i <= M; i++) {
    REP(j, Q[i].size()) { pq.push(Q[i][j]); }
    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>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < n; ++i)

int main() {
  int n, m;
  cin >> n >> m;
  int cnt = 0;
  vector<vector<int>> w(m);
  priority_queue<int> que;
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    if (a > m + 1)
      continue;
    w[a].emplace_back(b);
  }
  ll ans = 0;
  for (int i = 1; i < m + 1; i++) {
    for (auto j : w[i]) {
      que.push(j);
    }
    if (!que.empty()) {
      ans += que.top();
      que.pop();
    }
  }
  cout << ans;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  int cnt = 0;
  vector<vector<int>> w(m + 2);
  priority_queue<int> que;
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    if (a > m + 1)
      continue;
    w[a].emplace_back(b);
  }
  ll ans = 0;
  for (int i = 1; i < m + 1; i++) {
    for (auto j : w[i]) {
      que.push(j);
    }
    if (!que.empty()) {
      ans += que.top();
      que.pop();
    }
  }
  cout << ans;
}
Problem p02948 (C++)

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

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

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


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

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

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;

typedef pair<int, int> P;

vector<int> t[100002];

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

  for (int i = 0; i < n; i++) {
    P p;
    cin >> p.second >> p.first;
    t[m - p.second].push_back(p.first);
  }

  priority_queue<int, vector<int>, greater<int>> que;
  for (int i = 0; i < m; i++) {
    if (t[i].size() == 0) {
      continue;
    }

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


Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;

typedef pair<int, int> P;

vector<int> t[100002];

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

  for (int i = 0; i < n; i++) {
    P p;
    cin >> p.second >> p.first;
    if (m - p.second >= 0) {
      t[m - p.second].push_back(p.first);
    }
  }

  priority_queue<int, vector<int>, greater<int>> que;
  for (int i = 0; i < m; i++) {
    if (t[i].size() == 0) {
      continue;
    }

    for (int j = 0; j < t[i].size(); j++) {
      que.push(t[i][j]);
      if (que.size() > i + 1) {
        que.pop();
      }
    }
  }
  int ans = 0;
  while (!que.empty()) {
    ans += que.top();
    que.pop();
  }
  cout << ans << endl;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <vector>

std::priority_queue<int> A;
std::vector<int> B[10005];

int main() {
  int N, M;
  scanf("%d %d", &N, &M);
  int temp1, temp2;
  for (int i = 0; i < N; i++) {
    scanf("%d %d", &temp1, &temp2);
    B[temp1].push_back(temp2);
  }
  long long ans = 0;
  for (int i = 1; i <= M; i++) {
    // printf("i=%d\n",i);
    // printf("size=%lu\n",B[i].size());
    for (int j = 0; j < B[i].size(); j++) {
      A.push(B[i][j]);
    }
    if (!A.empty()) {
      ans += A.top();
      A.pop();
    }
  }

  printf("%lld\n", ans);
  return 0;
}

Fixed submission:
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <vector>

std::priority_queue<int> A;
std::vector<int> B[100005];

int main() {
  int N, M;
  scanf("%d %d", &N, &M);
  int temp1, temp2;
  for (int i = 0; i < N; i++) {
    scanf("%d %d", &temp1, &temp2);
    B[temp1].push_back(temp2);
  }
  long long ans = 0;
  for (int i = 1; i <= M; i++) {
    // printf("i=%d\n",i);
    // printf("size=%lu\n",B[i].size());
    for (int j = 0; j < B[i].size(); j++) {
      A.push(B[i][j]);
    }
    if (!A.empty()) {
      ans += A.top();
      A.pop();
    }
  }

  printf("%lld\n", ans);
  return 0;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

const int N = 100001;
const int M = 100001;

struct S {
  int a, b;
  S(int _a, int _b) {
    a = _a;
    b = _b;
  }
  bool operator<(const S &o) const { return a < o.a; }
};

int main() {
  int n, m;
  cin >> n >> m;
  vector<S> sb;
  int ma = 0;
  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    if (ma < a)
      ma = a;
    sb.push_back(S(a, b));
  }
  sort(sb.begin(), sb.end());

  long long ans = 0;
  priority_queue<int> que;
  int st = 0;
  for (int i = m - 1; i >= 0; --i) {
    for (; st < sb.size(); ++st) {
      if (sb[st].a + i <= m) {
        que.push(sb[st].b);
      } else
        break;
    }
    ans += que.top();
    que.pop();
  }
  cout << ans << endl;

  return 0;
}

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

const int N = 100001;
const int M = 100001;

struct S {
  int a, b;
  S(int _a, int _b) {
    a = _a;
    b = _b;
  }
  bool operator<(const S &o) const { return a < o.a; }
};

int main() {
  int n, m;
  cin >> n >> m;
  vector<S> sb;
  int ma = 0;
  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    if (ma < a)
      ma = a;
    sb.push_back(S(a, b));
  }
  sort(sb.begin(), sb.end());

  long long ans = 0;
  priority_queue<int> que;
  int st = 0;
  for (int i = m - 1; i >= 0; --i) {
    for (; st < sb.size(); ++st) {
      if (sb[st].a + i <= m) {
        que.push(sb[st].b);
      } else
        break;
    }
    if (que.size() > 0) {
      ans += que.top();
      que.pop();
    }
  }
  cout << ans << endl;

  return 0;
}
Problem p02948 (C++)

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> vec(N);
  rep(i, N) { cin >> vec[i].first >> vec[i].second; }
  sort(all(vec));
  priority_queue<int> pque;
  rep(i, N) { pque.push(0); }
  int count = 0;
  int ans = 0;
  for (int i = 1; i <= M; i++) {
    while (true) {
      if (count >= N) {
        break;
      } else if (vec[count].first != i) {
        break;
      } else {
        pque.push(vec[count].second);
        count++;
      }
    }
    ans += pque.top();
    pque.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++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(), v.end()
typedef long long ll;

int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> vec(N);
  rep(i, N) { cin >> vec[i].first >> vec[i].second; }
  sort(all(vec));
  priority_queue<int> pque;
  rep(i, 100005) { pque.push(0); }
  int count = 0;
  int ans = 0;
  for (int i = 1; i <= M; i++) {
    while (true) {
      if (count >= N) {
        break;
      } else if (vec[count].first != i) {
        break;
      } else {
        pque.push(vec[count].second);
        count++;
      }
    }
    ans += pque.top();
    pque.pop();
  }
  cout << ans << endl;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, start, end) for (int i = start; i < (int)(end); ++i)
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> jobs(m);
  rep(i, 0, n) {
    int a, b;
    cin >> a >> b;
    jobs[a - 1].push_back(b);
  }
  priority_queue<int> q;
  ll ans = 0;
  rep(i, 0, m) {
    for (int j : jobs[i]) {
      q.push(j);
    }
    if (q.empty())
      continue;
    ans += q.top();
    q.pop();
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, start, end) for (int i = start; i < (int)(end); ++i)
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> jobs(m);
  rep(i, 0, n) {
    int a, b;
    cin >> a >> b;
    if (m < a)
      continue;
    jobs[a - 1].push_back(b);
  }
  priority_queue<int> q;
  ll ans = 0;
  rep(i, 0, m) {
    for (int j : jobs[i]) {
      q.push(j);
    }
    if (q.empty())
      continue;
    ans += q.top();
    q.pop();
  }
  cout << ans << endl;
  return 0;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;

struct node {
  int index;
  int time;
  int cost;
};

struct CustomCompare {
  bool operator()(const node &l, const node &r) {
    if (l.cost == r.cost) {
      return l.time < r.time;
    } else {
      return l.cost < r.cost;
    }
  }
};

bool contains(vector<int> v, int target) {
  return std::find(v.begin(), v.end(), target) != v.end();
}

int main() {
  int n, m;
  cin >> n >> m;
  int a, b;
  priority_queue<node, vector<node>, CustomCompare> queue[m + 1];
  for (int i = 1; i <= n; i++) {
    cin >> a >> b;
    node g = {i, a, b};
    queue[a].push(g);
  }
  long long ans = 0;
  priority_queue<node, vector<node>, CustomCompare> worklist;
  for (int i = 1; i <= m; i++) {
    while (!queue[i].empty()) {
      worklist.push(queue[i].top());
      queue[i].pop();
    }
    if (!worklist.empty()) {
      node work = worklist.top();
      ans += work.cost;
      worklist.pop();
    }
  }
  cout << ans << endl;
  return 0;
}

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

struct node {
  int index;
  int time;
  int cost;
};

struct CustomCompare {
  bool operator()(const node &l, const node &r) {
    if (l.cost == r.cost) {
      return l.time < r.time;
    } else {
      return l.cost < r.cost;
    }
  }
};

bool contains(vector<int> v, int target) {
  return std::find(v.begin(), v.end(), target) != v.end();
}

int main() {
  int n, m;
  cin >> n >> m;
  int a, b;
  priority_queue<node, vector<node>, CustomCompare> queue[m + 1];
  for (int i = 1; i <= n; i++) {
    cin >> a >> b;
    node g = {i, a, b};
    if (a <= m) {
      queue[a].push(g);
    }
  }
  long long ans = 0;
  priority_queue<node, vector<node>, CustomCompare> worklist;
  for (int i = 1; i <= m; i++) {
    while (!queue[i].empty()) {
      worklist.push(queue[i].top());
      queue[i].pop();
    }
    if (!worklist.empty()) {
      node work = worklist.top();
      ans += work.cost;
      worklist.pop();
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
  ll a, b, n, m, tmp, sum = 0, day, ad;
  cin >> n >> m;
  vector<ll> n_list[10001];
  day = 0;
  priority_queue<ll> que;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    n_list[a].push_back(b);
  }
  for (int i = m - 1; i >= 0; i--) {
    tmp = m - i;
    for (int j = 0; j < n_list[tmp].size(); j++) {
      que.push(n_list[tmp][j]);
    }
    if (!que.empty()) {
      sum += que.top();
      que.pop();
    }
  }
  cout << sum << endl;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
  ll a, b, n, m, tmp, sum = 0, day, ad;
  cin >> n >> m;
  vector<ll> n_list[100001];
  day = 0;
  priority_queue<ll> que;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    n_list[a].push_back(b);
  }
  for (int i = m - 1; i >= 0; i--) {
    tmp = m - i;
    for (int j = 0; j < n_list[tmp].size(); j++) {
      que.push(n_list[tmp][j]);
    }
    if (!que.empty()) {
      sum += que.top();
      que.pop();
    }
  }
  cout << sum << endl;
}
Problem p02948 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <queue>

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> v[M];
  int A, B;
  for (int i = 0; i < N; ++i) {
    cin >> A >> B;
    if (A > M)
      continue;
    v[A - 1].push_back(B);
  }
  priority_queue<int> que;
  int ans = 0;
  for (int i = 0; i < M; ++i) {
    for (int x : v[i]) {
      que.push(x);
    }
    if (!que.empty()) {
      ans += que.top();
      que.pop();
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> v(M);
  int A, B;
  for (int i = 0; i < N; ++i) {
    cin >> A >> B;
    if (A > M)
      continue;
    v[A - 1].push_back(B);
  }
  priority_queue<int> que;
  int ans = 0;
  for (int i = 0; i < M; ++i) {
    for (int x : v[i]) {
      que.push(x);
    }
    if (!que.empty()) {
      ans += que.top();
      que.pop();
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02948 (C++)

Buggy submission (status: Runtime Error):
//============================================================================
// Name        : d.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <queue>
#include <vector>
using namespace std;

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

Fixed submission:
//============================================================================
// Name        : d.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <queue>
#include <vector>
using namespace std;

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

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

int main() {
  int n, m;
  cin >> n >> m;
  ll ans = 0;
  vector<vector<int>> table(m + 1, vector<int>());
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    table[a].push_back(b);
  }
  priority_queue<int> pq;
  for (int i = 1; i < m + 1; i++) {
    for (auto ele : table[i]) {
      pq.push(ele);
    }
    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;
  ll ans = 0;
  vector<vector<int>> table(m + 1, vector<int>());
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    if (a <= m)
      table[a].push_back(b);
  }
  priority_queue<int> pq;
  for (int i = 1; i < m + 1; i++) {
    for (auto ele : table[i]) {
      pq.push(ele);
    }
    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>
using namespace std;

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
typedef long long ll;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> v[M];
  rep(i, N) {
    int a, b;
    cin >> a >> b;
    a--;
    v[a].pb(b);
  }
  priority_queue<int> que;
  ll ans = 0;
  rep(i, M) {
    for (int x : v[i]) {
      que.push(x);
    }
    if (!que.empty()) {
      ans += que.top();
      que.pop();
    }
  }
  cout << ans << endl;
  return 0;
}

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
typedef long long ll;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> v[M];
  rep(i, N) {
    int a, b;
    cin >> a >> b;
    if (a > M)
      continue;
    a--;
    v[a].pb(b);
  }
  priority_queue<int> que;
  ll ans = 0;
  rep(i, M) {
    for (int x : v[i]) {
      que.push(x);
    }
    if (!que.empty()) {
      ans += que.top();
      que.pop();
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02948 (C++)

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

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> jobs(M);
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    jobs[M - a].push_back(b);
  }
  long long int ans = 0;
  priority_queue<int> pqueue;
  for (int i = 1; i <= M; i++) {
    for (int b : jobs[M - i]) {
      pqueue.push(b);
    }
    if (!pqueue.empty()) {
      ans += pqueue.top();
      pqueue.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>> jobs(M);
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    if (a > M)
      continue;
    jobs[M - a].push_back(b);
  }
  long long int ans = 0;
  priority_queue<int> pqueue;
  for (int i = 1; i <= M; i++) {
    for (int b : jobs[M - i]) {
      pqueue.push(b);
    }
    if (!pqueue.empty()) {
      ans += pqueue.top();
      pqueue.pop();
    }
  }

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