alexjercan/bugnet huggingface dataset:
Problem p00099 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <map>
#include <string.h>
using namespace std;
int main() {
  long n, q;
  cin >> n >> q;
  int MAX_N = 0;
  long MAX_POW = 1;
  while (q > MAX_POW)
    MAX_N++, MAX_POW *= 2;
  long a[300000] = {0};
  long num[300000];
  memset(num, -1, sizeof(num));
  map<long, long> f;
  long MAX_POW_tmp = MAX_POW;
  long curr = 0;
  for (long i = 0; i < q; i++) {
    long tmp, TMP;
    cin >> tmp >> TMP;
    tmp--; // tmpはinputでは1base、処理は0base
    if (f.find(tmp) == f.end())
      f[tmp] = curr++, num[f[tmp]] = tmp;
    a[f[tmp]] += TMP;
    long acc = 0;
    MAX_POW = MAX_POW_tmp;
    long next_N = f[tmp] / 2;
    // 以下seg tree
    for (int j = 1; j <= MAX_N; j++) {
      long prev_N = next_N * 2;
      if (a[acc + prev_N] > a[acc + prev_N + 1] ||
          (a[acc + prev_N] == a[acc + prev_N + 1] &&
           num[acc + prev_N] < num[acc + prev_N + 1]))
        a[acc + next_N + MAX_POW] = a[acc + prev_N],
                         num[acc + next_N + MAX_POW] = num[acc + prev_N];
      else
        a[acc + next_N + MAX_POW] = a[acc + prev_N + 1],
                         num[acc + next_N + MAX_POW] = num[acc + prev_N + 1];
      acc += MAX_POW;
      MAX_POW /= 2;
      next_N /= 2;
    }
    // 以上seg tree
    cout << num[acc] + 1 << ' ' << a[acc] << '\\n';
  }
}

Error: -11

Fixed submission:

#include <iostream>
#include <string.h>
using namespace std;
int main() {
  long n, q;
  cin >> n >> q;
  int MAX_N = 0;
  long MAX_POW = 1;
  while (q > MAX_POW)
    MAX_N++, MAX_POW *= 2;
  long f[1000000];
  memset(f, -1, sizeof(f));
  long a[300000] = {0};
  long num[300000];
  memset(num, -1, sizeof(num));
  long MAX_POW_tmp = MAX_POW;
  long curr = 0;
  for (long i = 0; i < q; i++) {
    long tmp, TMP;
    cin >> tmp >> TMP;
    tmp--; // tmpはinputでは1base、処理は0base
    if (f[tmp] == -1)
      f[tmp] = curr++;
    a[f[tmp]] += TMP;
    num[f[tmp]] = tmp;
    long acc = 0;
    MAX_POW = MAX_POW_tmp;
    long next_N = f[tmp] / 2;
    // 以下seg tree
    for (int j = 1; j <= MAX_N; j++) {
      if (a[acc + next_N * 2] >= a[acc + next_N * 2 + 1])
        a[acc + next_N + MAX_POW] = a[acc + next_N * 2],
                         num[acc + next_N + MAX_POW] = num[acc + next_N * 2];
      else
        a[acc + next_N + MAX_POW] = a[acc + next_N * 2 + 1],
                         num[acc + next_N + MAX_POW] =
                             num[acc + next_N * 2 + 1];
      acc += MAX_POW;
      MAX_POW /= 2;
      next_N /= 2;
    }
    // 以上seg tree
    cout << num[acc] + 1 << ' ' << a[acc] << '\\n';
  }
}
Problem p00099 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i, m) for (long long i = 0; i < m; i++)
#define FOR(i, n, m) for (long long i = n; i < m; i++)
#define DUMP(a)                                                                \\
  for (long long dump = 0; dump < (ll)a.size(); dump++) {                      \\
    cout << a[dump];                                                           \\
    if (dump != n - 1)                                                         \\
      cout << " ";                                                             \\
    else                                                                       \\
      cout << endl;                                                            \\
  }
#define ALL(v) v.begin(), v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

/*
 貪欲
 ?決定問題 必ず解に含まれる(含むように変換できる)ものから決めていく
 みんプロ本選B ?最適化問題
 任意の解から評価を落とさず解に含められるようなものから決めていく
 区間スケジューリングとか
 ?
 */

/*
 DP
 ?DPはある程度決め打ちをするべき(解を帰納的に構成できないか？)
 */

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, q;
  cin >> n >> q;
  vector<ll> cnt(n, 0);
  priority_queue<P> que;
  REP(i, n) que.push(P(0, -i));
  REP(i, q) {
    ll a, v;
    cin >> a >> v;
    a--;
    cnt[a] += v;
    que.push(P(cnt[a], -a));
    while (cnt[-que.top().second] != que.top().first)
      que.pop();
    cout << -que.top().second + 1 << " " << que.top().first << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define REP(i, N) for (ll i = 0; i < N; ++i)
#define FOR(i, a, b) for (ll i = a; i < b; ++i)
#define ALL(a) (a).begin(), (a).end()
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int qx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int qy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(void) {
  ll n, q;
  cin >> n >> q;
  vector<ll> hoge(n, 0);
  vector<P> hogeho(n);
  REP(i, n) {
    hogeho[i].first = 0;
    hogeho[i].second = n - i;
  }
  sort(ALL(hogeho));
  REP(i, q) {
    ll a, v;
    cin >> a >> v;
    --a;
    ll gomi = hoge[a];
    hoge[a] += v;
    vector<P>::iterator ite;
    ite = lower_bound(ALL(hogeho), P(gomi, n - a));
    (*ite).first = hoge[a];
    sort(ALL(hogeho));
    cout << n + 1 - hogeho[n - 1].second << " " << hogeho[n - 1].first << endl;
  }
}
Problem p00099 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <queue>

using namespace std;
typedef pair<int, int> P;
int main() {
  int n, q;
  cin >> n >> q;
  int a[n + 1];
  priority_queue<P> p;

  for (int k = 0; k < n + 1; k++) {
    a[k] = 0;
  }

  int s, v;
  for (int i = 0; i < q; i++) {
    cin >> s >> v;
    a[s] += v;
    p.push(P(a[s], -s));

    for (;;) {
      P t = p.top();
      if (t.first == a[-t.second]) {
        cout << -t.second << " " << t.first << endl;
        break;
      }
      p.pop();
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int n, q;
  cin >> n >> q;
  int a[n];
  for (int k = 0; k < n; k++) {
    a[k] = 0;
  }
  for (int i = 0; i < q; i++) {
    int s, v;
    cin >> s >> v;
    a[s - 1] += v;
    int max = -150;
    int maxj = 0;
    for (int j = 0; j < n; j++) {
      if (max < a[j]) {
        max = a[j];
        maxj = j;
      }
    }
    cout << maxj + 1 << " " << a[maxj] << endl;
  }
  return 0;
}
Problem p00099 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

struct S {
  int a, v;
};

bool operator<(S a, S b) { return a.v > b.v || (a.v == b.v && a.a < b.a); }

int main() {

  int n, q, a, v;
  vector<S> fish;
  vector<S> sort_fish;
  S av;
  int max = 0, max_i = 1;

  cin >> n >> q;

  for (int i = 0; i < n; i++) {
    av.a = i + 1, av.v = 0;
    fish.push_back(av);
  }

  while (q-- > 0) {
    cin >> a >> v;
    fish[a - 1].v += v;
    if (v < 0) {
      if (max_i == a) {
        sort_fish = fish;
        sort(sort_fish.begin(), sort_fish.end());
        cout << sort_fish[0].a << " " << sort_fish[0].v << endl;
        max = sort_fish[0].v, max_i = sort_fish[0].a;
      } else {
        cout << max_i << " " << max << endl;
      }
    } else {
      if (max < fish[a - 1].v || (max == fish[a - 1].v && max_i >= a))
        max = fish[a - 1].v, max_i = a;
      cout << max_i << " " << max << endl;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

struct S {
  int a, v;
};

bool operator<(S a, S b) { return a.v > b.v || (a.v == b.v && a.a < b.a); }

int main() {

  int n, q, a, v;
  vector<S> fish;
  vector<S> sort_fish;
  S av;
  int max = 0, max_i = 1;

  cin >> n >> q;

  for (int i = 0; i < n; i++) {
    av.a = i + 1, av.v = 0;
    fish.push_back(av);
  }

  while (q-- > 0) {
    cin >> a >> v;
    fish[a - 1].v += v;
    if (v < 0) {
      if (a == sort_fish[0].a) {
        sort_fish = fish;
        sort(sort_fish.begin(), sort_fish.end());
      }
      cout << sort_fish[0].a << " " << sort_fish[0].v << endl;
      max = sort_fish[0].v, max_i = sort_fish[0].a;
    } else {
      if (max < fish[a - 1].v || (max == fish[a - 1].v && max_i >= a))
        max = fish[a - 1].v, max_i = a;
      cout << max_i << " " << max << endl;
    }
  }

  return 0;
}
Problem p00099 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
#include <queue>
#include <utility>
using namespace std;
typedef pair<int, int> P;

int A[1000001] = {0};
int main() {
  int n, q, a, b;
  int f = 0;
  cin >> n >> q;
  priority_queue<P> pp;
  pp.push(P(0, -1));

  for (int i = 0; i < q; i++) {
    cin >> a >> b;
    A[a] += b;
    pp.push(P(A[a], -a));
    while (1) {
      int x = -pp.top().second;
      int y = pp.top().first;
      if (A[x] == y) {
        cout << x << " " << y << endl;
        break;
      }
      pp.pop();
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n, q, a, b;
  int v[1000000];
  int f = 0;
  while (cin >> n >> q) {
    if (f)
      cout << endl;
    fill(v, v + n, 0);
    for (int i = 0; i < q; i++) {
      cin >> a >> b;
      v[a - 1] += b;
      int max = 0, ret;
      for (int j = 0; j < n; j++) {
        if (max < v[j]) {
          max = v[j];
          ret = j + 1;
        }
      }
      cout << ret << " " << max << endl;
    }
    f = 1;
  }
  return 0;
}
Problem p00099 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

typedef pair<int, int> P;

int main(void) {

  int n, q, cnt[1000001];
  priority_queue<P> que;
  que.push(P(0, -1));
  fill(cnt, cnt + 1000001, 0);

  cin >> n >> q;
  while (q--) {
    int a, v;
    cin >> a >> v;
    cnt[a] += v;
    que.push(P(cnt[a], -a));
    while (true) {
      P res = que.top();
      if (res.first == cnt[-res.second]) {
        cout << -res.second << " " << res.first << endl;
        break;
      }
      que.pop();
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>

using namespace std;

int main(void) {

  int n, q, p[1000001], a, v;
  fill(p, p + 1000001, 0);

  cin >> n >> q;

  while (q--) {
    cin >> a >> v;
    p[a] += v;
    int m = 0;
    for (int i = 1; i <= n; i++)
      m = max(m, p[i]);
    for (int i = 1; i <= n; i++) {
      if (p[i] == m) {
        cout << i << " " << p[i] << endl;
        break;
      }
    }
  }
  return 0;
}
Problem p00099 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>

using namespace std;

pair<int, int> seg[1 << 21];

void add(int k, int x) {
  k += (1 << 20) - 1;
  seg[k].first = k - (1 << 20) + 1;
  seg[k].second += x;

  while (k) {
    k = (k - 1) / 2;
    if (seg[k * 2 + 2].second > seg[k * 2 + 1].second) {
      seg[k] = seg[k * 2 + 2];
    } else {
      seg[k] = seg[k * 2 + 1];
    }
  }
  return;
}

pair<int, int> getMax(int a, int b, int k = 0, int l = 0, int r = 1 << 20) {
  if (b <= l || r <= a)
    return (make_pair(-999999999, -999999999));

  if (a <= l && r <= b)
    return (seg[k]);

  pair<int, int> lch = getMax(a, b, k * 2 + 1, l, (l + r) / 2),
                 rch = getMax(a, b, k * 2 + 2, (l + r) / 2, r);

  if (rch.second > lch.second)
    return (rch);
  return (lch);
}

int main() {
  int n, q;

  scanf("%d %d", &n, &q);
  for (int i = 0; i < n; i++)
    add(i, 0);

  for (int i = 0; i < q; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    add(a - 1, b);

    pair<int, int> x = getMax(0, n);
    printf("%d %d\\n", x.first + 1, x.second);
  }

  return (0);
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>

using namespace std;

pair<int, int> seg[1 << 19];

void add(int k, int x) {
  k += (1 << 18) - 1;
  seg[k].first = k - (1 << 18) + 1;
  seg[k].second += x;

  while (k) {
    k = (k - 1) / 2;
    if (seg[k * 2 + 2].second > seg[k * 2 + 1].second) {
      seg[k] = seg[k * 2 + 2];
    } else {
      seg[k] = seg[k * 2 + 1];
    }
  }
  return;
}

pair<int, int> getMax(int a, int b, int k = 0, int l = 0, int r = 1 << 18) {
  if (b <= l || r <= a)
    return (make_pair(-999999999, -999999999));

  if (a <= l && r <= b)
    return (seg[k]);

  pair<int, int> lch = getMax(a, b, k * 2 + 1, l, (l + r) / 2),
                 rch = getMax(a, b, k * 2 + 2, (l + r) / 2, r);

  if (rch.second > lch.second)
    return (rch);
  return (lch);
}

int main() {
  int n, q;

  scanf("%d %d", &n, &q);
  for (int i = 0; i < n; i++)
    add(i, 0);

  for (int i = 0; i < q; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    add(a - 1, b);

    pair<int, int> x = getMax(0, n);
    if (x.first < 0)
      return (0);
    printf("%d %d\\n", x.first + 1, x.second);
  }

  return (0);
}
Problem p00099 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <sstream>
#include <stdlib.h>

using namespace std;

int find_max(int *arr, int size) {
  int max = -1;
  for (int i = 0; i < size; i++) {
    if (arr[max] < arr[i]) {
      max = i;
    }
  }
  return max;
}

int main() {
  int n, q;
  cin >> n >> q;
  int *m = (int *)malloc(sizeof(int) * n);

  for (int i = 0; i < n; i++)
    m[i] = 0;

  int max = -1;
  for (int i = 0; i < q; i++) {
    int a, v;
    cin >> a >> v;
    m[a - 1] += v;

    if (v > 0) {
      if (m[max] < m[a - 1]) {
        max = a - 1;
      } else if (m[max] == m[a - 1]) {
        for (int j = 0; j < n; j++) {
          if (m[max] == m[j]) {
            max = j;
            break;
          }
        }
      }
    } else {
      max = find_max(m, n);
    }

    cout << max + 1 << " " << m[max] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <sstream>
#include <stdlib.h>

using namespace std;

int *max(int *arr, int size, int *mxi) {
  for (int i = 0; i < size; i++) {
    if (mxi[1] < arr[i]) {
      mxi[0] = i;
      mxi[1] = arr[i];
    }
  }
  return mxi;
}

int main() {
  int n, q;
  cin >> n >> q;
  int *m = (int *)malloc(sizeof(int) * n);

  for (int i = 0; i < n; i++)
    m[i] = 0;

  for (int i = 0; i < q; i++) {
    int a, v;
    cin >> a >> v;
    m[a - 1] += v;
    int mxi[] = {-1, -1};
    max(m, n, mxi);
    cout << mxi[0] + 1 << " " << mxi[1] << "\\n";
  }
}
Problem p00099 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <functional>
#include <iostream>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>

#define CI cin >>
#define CO cout <<
#define E << endl;
#define F(i, max) (for (int i = 0; i < max; ++i))

using namespace std;

int n = 0;
int num = 0;
int fish = 0;
int event = 0;
int max_[2] = {};
int maxx[2] = {};
vector<int> part;

int main(void) {
  CI n >> event;

  max_[1] = 0;

  part.resize(n, 0);

  for (int i = 0; i < event; ++i) {
    CI num;
    CI fish;
    part[num - 1] += fish;

    if (fish > 0) {
      if (part[num - 1] > max_[1]) {
        max_[0] = num;
        max_[1] = part[num - 1];
      } else {
        if (part[num - 1] == max_[1]) {
          if (num < max_[0]) {
            max_[0] = num;
          }
        }
      }
    } else {
      if (max_[0] == num) {
        for (int j = 0; j < n; ++j) {
          if (maxx[1] < part[j]) {
            maxx[1] = part[j];
            maxx[0] = j + 1;
          }
        }
        max_[0] = maxx[0];
        max_[1] = maxx[1];
        maxx[0] = 0;
        maxx[1] = 0;
      }
    }

    CO max_[0] << ' ' << max_[1] E
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <functional>
#include <iostream>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>

#define CI cin >>
#define CO cout <<
#define E << endl;
#define F(i, max) (for (int i = 0; i < max; ++i))

using namespace std;

int n = 0;
int num = 0;
int fish = 0;
int event = 0;
int max_[2] = {};
int maxx = 0;
vector<int> part;

int main(void) {
  CI n >> event;

  part.resize(n, 0);

  for (int i = 0; i < event; ++i) {
    CI num;
    CI fish;
    part[num - 1] += fish;
    max_[1] = 0;
    for (int j = 0; j < n; ++j) {
      if (part[j] > max_[1]) {
        max_[1] = part[j];
        max_[0] = j + 1;
      }
    }

    CO max_[0] << ' ' << max_[1] E
  }

  return 0;
}
Problem p00099 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int a[3000000][2] = {}; //
void f(int z) {
  if (a[z * 2][1] >= a[z * 2 + 1][1]) {
    a[z][0] = a[z * 2][0];
    a[z][1] = a[z * 2][1];
  } else {
    a[z][0] = a[z * 2 + 1][0];
    a[z][1] = a[z * 2 + 1][1];
  }
  if (z != 1)
    f(z / 2);
}

int main() {
  int m, x, y, n;
  int q = 0;
  cin >> n >> m;
  for (q = 1; q < n; q = q * 2)
    ;
  for (int i = 1; i <= n; i++)
    a[i + q - 1][0] = i;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    a[q + x - 1][1] += y;
    f((q + x - 1) / 2);
    cout << a[1][0] << ' ' << a[1][1] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int a[3000000][2] = {};
void f(int z) {
  for (int i = 0; i < z; i++) {
    if (a[(z + i) * 2][1] >= a[(z + i) * 2 + 1][1]) {
      a[z + i][0] = a[(z + i) * 2][0];
      a[z + i][1] = a[(z + i) * 2][1];
    } else {
      a[z + i][0] = a[(z + i) * 2 + 1][0];
      a[z + i][1] = a[(z + i) * 2 + 1][1];
    }
  }
  if (z != 1)
    f(z / 2);
}

int main() {
  int m, x, y, n;
  int q = 0;
  cin >> n >> m;
  for (q = 1; q < n; q = q * 2) {
  }
  for (int i = 1; i <= n; i++)
    a[i + q - 1][0] = i;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    a[q + x - 1][1] += y;
    f(q / 2);
    cout << a[1][0] << ' ' << a[1][1] << endl;
  }
  return 0;
}
Problem p00099 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <set>

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

using namespace std;

int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  static int num[1000001];
  set<pair<int, int>> S;
  S.insert(make_pair(0, 1));
  rep(_, q) {
    int a, v;
    scanf("%d%d", &a, &v);
    if (num[a] > 0)
      S.erase(S.find(make_pair(-num[a], a)));
    num[a] += v;
    if (num[a] > 0)
      S.insert(make_pair(-num[a], a));
    printf("%d %d\\n", S.begin()->second, -S.begin()->first);
  }

  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <set>

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

using namespace std;

int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  static int num[100001];
  multiset<pair<int, int>> S;
  S.insert(make_pair(0, 0));
  rep(_, q) {
    int a, v;
    scanf("%d%d", &a, &v);
    if (num[a] > 0)
      S.erase(S.find(make_pair(-num[a], a)));
    num[a] += v;
    if (num[a] > 0)
      S.insert(make_pair(-num[a], a));
    printf("%d %d\\n", S.begin()->second, -S.begin()->first);
  }

  return 0;
}
Problem p00099 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <map>
#include <queue>

using namespace std;

typedef pair<int, int> P;

int n, q;
int fish[1000001];

int main() {
  cin >> n >> q;

  priority_queue<P> pq;

  for (int i = 0; i < q; i++) {
    int a, v;
    cin >> a >> v;
    fish[a] += v;
    pq.push(P(fish[a], a * (-1)));

    while (!pq.empty()) {
      P p = pq.top();
      p.second *= -1;
      if (p.first == fish[p.second]) {
        cout << p.second << ' ' << p.first << endl;
        break;
      }
      pq.pop();
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <string>
using namespace std;

typedef pair<int, int> P;

void q99() {
  int n, q;

  for (; cin >> n >> q;) {
    // first??§???????????????????????????first??????second??§??????
    auto comp = [](P l, P r) {
      return l.first != r.first ? l.first < r.first : l.second < r.second;
    };
    priority_queue<P, vector<P>, decltype(comp)> queue(comp);
    int fish[100000];
    memset(fish, 0, sizeof(fish));

    for (int i = 0; i < q; i++) {
      int a_i, v_i;
      cin >> a_i >> v_i;
      fish[a_i] += v_i;
      queue.push(make_pair(fish[a_i], -a_i));
      for (; !queue.empty();) {
        auto top = queue.top();
        if (top.first == fish[-top.second]) {
          cout << -top.second << " " << top.first << endl;
          break;
        }
        queue.pop();
      }
    }
  }
}

int main() {
  q99();
  return 0;
}
Problem p00099 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
struct pr {
  bool operator()(const int *p, const int *q) const {
    if (*p == *q)
      return p < q;
    else
      return *p > *q;
  }
};
int main() {
  int i;
  int n, m;
  scanf("%d%d", &n, &m);
  int a[1000000] = {};
  set<int *, pr> b;
  for (i = 0; i < n; ++i)
    b.insert(a + i);
  while (m--) {
    int p, q;
    scanf("%d%d", &p, &q);
    --p;
    set<int *, pr>::iterator it = b.find(a + p);
    int *r = *it;
    b.erase(it);
    a[p] += q;
    b.insert(r);
    printf("%d %d\\n", *b.begin() - a + 1, **b.begin());
  }
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
bool pr(const int *p, const int *q) {
  if (*p == *q)
    return p < q;
  else
    return *p > *q;
}
int main() {
  int i;
  int n, m;
  scanf("%d%d", &n, &m);
  int a[1000000] = {};
  int *b[1000000];
  for (i = 0; i < n; ++i)
    b[i] = a + i;
  while (m--) {
    int p, q;
    scanf("%d%d", &p, &q);
    --p;
    int **r = lower_bound(b, b + n, a + p, pr);
    int *s = *r;
    a[p] += q;
    int **t = lower_bound(b, r, s, pr), **u = lower_bound(r + 1, b + n, s, pr);
    if (false) {
    } else if (t == r && u == r + 1) {
    } else if (t == r) {
      memmove(r, r + 1, sizeof(int *) * (u - r - 1));
      *(u - 1) = s;
    } else if (u == r + 1) {
      memmove(t + 1, t, sizeof(int *) * (r - t));
      *t = s;
    }
    printf("%d %d\\n", b[0] - a + 1, *b[0]);
  }
  return 0;
}
Problem p00099 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n, q, a, v, fish[1000001] = {};
  cin >> n >> q;
  priority_queue<pair<int, int>> Q;
  Q.push(make_pair(0, -1));
  while (q--) {
    cin >> a >> v;
    fish[a] += v;
    Q.push(make_pair(fish[a], -a));
    while (Q.top().first > fish[-Q.top().second])
      Q.pop();
    cout << -Q.top().second << " " << Q.top().first << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;
#define MAX_EVENT 100000

int main() {
  int n, q, a, v, max_id, max_fish = -1;
  cin >> n >> q;
  int *player_id = new int[MAX_EVENT + 1];
  int *player_fish = new int[MAX_EVENT + 1];
  int entry = 0;

  while (q--) {
    cin >> a >> v;
    auto v1 = v;
    for (int i = 0; i < entry; i++) {
      if (player_id[i] == a) {
        v1 = player_fish[i] += v;
        break;
      }
    }
    if (v == v1) {
      player_id[entry] = a;
      player_fish[entry++] = v;
    }
    if (v1 > max_fish || (v1 == max_fish && a < max_id)) {
      max_id = a;
      max_fish = v1;
    }
    if (v < 0 && max_id == a) {
      max_fish = -1;
      for (int i = 0; i < entry; i++) {
        if (player_fish[i] > max_fish ||
            (player_fish[i] == max_fish && player_id[i] < max_id)) {
          max_id = player_id[i];
          max_fish = player_fish[i];
        }
      }
    }
    cout << max_id << " " << max_fish << endl;
  }
}