alexjercan/bugnet huggingface dataset:
Problem p00099 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <queue>

using namespace std;

#define reps(i, j, k) for (int i = j; i < k; i++)
#define rep(i, j) reps(i, 0, j)
typedef pair<int, int> Pii;
int fish[1000001];
int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  priority_queue<Pii> PQ;
  rep(i, q) {
    int a, v;
    scanf("%d%d", &a, &v);
    fish[a] += v;
    PQ.push(Pii(fish[a], -a));
    while (!PQ.empty()) {
      Pii p = PQ.top();
      if (p.first == fish[-p.second]) {
        printf("%d %d\\n", -p.second, p.first);
        break;
      }
      PQ.pop();
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <queue>

using namespace std;

#define reps(i, j, k) for (int i = j; i < k; i++)
#define rep(i, j) reps(i, 0, j)
typedef pair<int, int> Pii;
int fish[1000001];
int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  priority_queue<Pii> PQ[2];
  rep(i, q) {
    int a, v;
    scanf("%d%d", &a, &v);
    fish[a] += v;
    PQ[i % 2].push(Pii(fish[a], -a));
    while (!PQ[i % 2].empty()) {
      Pii p = PQ[i % 2].top();
      PQ[i % 2].pop();
      if (p.second != -a) {
        PQ[1 - i % 2].push(p);
      } else {
        PQ[1 - i % 2].push(Pii(fish[a], -a));
      }
    }
    Pii p = PQ[1 - i % 2].top();
    PQ[1 - i % 2].pop();
    printf("%d %d\\n", -p.second, p.first);
    PQ[1 - i % 2].push(p);
  }
  return 0;
}
Problem p00099 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
const int MAX_N = 1e5 + 10;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, q;
  cin >> n >> q;
  priority_queue<pair<int, int>> result;
  vector<int> cnt(n + 1, 0);
  vector<pair<int, int>> ans;
  for (int i = 0; i < q; i++) {
    int a, v;
    cin >> a >> v;
    cnt[a] += v;
    result.push(make_pair(cnt[a], -a));
    while (not result.empty()) {
      pair<int, int> p = result.top();
      if (p.first == cnt[-p.second]) {
        ans.push_back(make_pair(-p.second, p.first));
        break;
      }
      result.pop();
    }
  }
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i].first << " " << ans[i].second << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, q;
  cin >> n >> q;
  priority_queue<pair<int, int>> result;
  vector<int> cnt(n + 1, 0), a(n), v(n);
  vector<pair<int, int>> ans;
  for (int i = 0; i < q; i++)
    cin >> a[i] >> v[i];
  for (int i = 0; i < q; i++) {
    cnt[a[i]] += v[i];
    if (result.size() > 0 && result.top().second == -a[i])
      result.pop();
    result.push(make_pair(cnt[a[i]], -a[i]));
    pair<int, int> p = result.top();
    ans.push_back(make_pair(-p.second, p.first));
  }
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i].first << " " << ans[i].second << endl;
  return 0;
}
Problem p00099 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <stdio.h>
#include <string.h>
#define min(a, b)                                                              \\
  { a > b ? b : a }
#define max(a, b)                                                              \\
  { a > b ? a : b }
using namespace std;

int N = 1000000;
int segment[1000000 * 2];
int id[1000000 * 2];

void q99() {
  int n, q;
  cin >> n >> q;

  for (int i = 0; i < N; i++) {
    id[i + N] = i;
  }
  for (int i = 0; i < q; i++) {
    int a, v;
    cin >> a >> v;
    segment[N + a - 1] += v;
    for (int j = (N + a - 1) >> 1; j > 0; j = j >> 1) {
      if (segment[j * 2] == segment[j * 2 + 1]) {
        segment[j] = segment[j * 2];
        id[j] = min(id[j * 2], id[j * 2 + 1]);
      } else if (segment[j * 2] > segment[j * 2 + 1]) {
        segment[j] = segment[j * 2];
        id[j] = id[j * 2];
      } else {
        segment[j] = segment[j * 2 + 1];
        id[j] = id[j * 2 + 1];
      }
    }
    cout << id[1] + 1 << " " << segment[1] << endl;
  }
}

int main() {
  q99();
  return 0;
}

Error: TLE

Fixed submission:


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

int N = 1000000;
long long int segment[1000000 * 2];
int id[1000000 * 2];

void q99() {
  int n, q;
  cin >> n >> q;

  for (int i = 0; i < N; i++) {
    id[i + N] = i;
  }

  for (int i = 0; i < q; i++) {
    int a, v;
    cin >> a >> v;
    segment[N + a - 1] += v;
    for (int j = (N + a - 1) >> 1; j >= 0; j = j >> 1) {
      if (segment[j * 2] < segment[j * 2 + 1]) {
        segment[j] = segment[j * 2 + 1];
        id[j] = id[j * 2 + 1];
      } else {
        segment[j] = segment[j * 2];
        id[j] = id[j * 2];
      }
    }
    cout << id[0] + 1 << " " << segment[0] << endl;
  }
}

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

#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n, q, a, v;
  int maxA, maxV;
  cin >> n >> q;
  vector<int> list(n, 0);
  maxA = maxV = 0;
  while (cin >> a >> v) {
    a--;
    list[a] += v;
    if (v > 0) {
      if (maxV < list[a]) {
        maxA = a;
        maxV = list[a];
      } else if (maxV == list[a]) {
        maxA = min(maxA, a);
      }
    }
    if (v < 0) {
      if (a == maxA) {
        maxV = -1;
        for (int i = 0; i < n; i++) {
          if (maxV < list[i]) {
            maxA = i;
            maxV = list[i];
          }
        }
      }
    }
    cout << maxA + 1 << " " << maxV << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <map>
using namespace std;
int main() {
  int n, q, a, v;
  int maxA = 1, maxV = 0;
  map<int, int> m;
  map<int, int>::iterator it;
  for (cin >> n >> q; cin >> a >> v;) {
    m[a] += v;
    if (v > 0) {
      if (maxV < m[a]) {
        maxA = a;
        maxV = m[a];
      } else if (maxV == m[a]) {
        maxA = min(maxA, a);
      }
    }
    if (v < 0) {
      maxV = -1;
      for (it = m.begin(); it != m.end(); it++) {
        if (maxV < it->second) {
          maxA = it->first;
          maxV = it->second;
        }
      }
    }
    cout << maxA << " " << maxV << endl;
  }
}
Problem p00099 (C++) — buggy submission, verdict: Time Limit Exceeded

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

typedef std::pair<int, int> P;

int main() {

  int n, q;
  std::cin >> n >> q;

  std::vector<int> v(n, 0);

  std::priority_queue<P> que;

  for (int i = 0; i < q; i++) {

    int a, b;
    std::cin >> a >> b;
    a--;

    v[a] += b;

    que.push(P(v[a], -a));

    while (!que.empty()) {
      P res = que.top();

      if (res.first == v[-res.second]) {
        std::cout << -res.second + 1 << " " << res.first << std::endl;
        break;
      }
      que.pop();
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <vector>

struct P {
  int first, second;
  P(int a, int b) : first(a), second(b) {}
};

bool ask(const P &lhs, const P &rhs) { return lhs.second > rhs.second; }

P calc(std::vector<P> v) {

  std::stable_sort(v.begin(), v.end(), ask);

  return P(v[0].first, v[0].second);
}

int main() {

  int n, q;
  std::cin >> n >> q;

  std::vector<P> v(n, P(0, 0));

  for (int i = 0; i < n; i++) {
    v[i].first = i + 1;
    v[i].second = 0;
  }

  for (int i = 0; i < q; i++) {

    int a, b;
    std::cin >> a >> b;
    a--;

    v[a].second += b;

    P res(calc(v));

    std::cout << res.first << " " << res.second << std::endl;
  }

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

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

int main() {
  int n, q, num, v;
  cin >> n >> q;

  vector<int> wakasagi(n + 1, 0);
  priority_queue<pair<int, int>> pq;
  for (int i = 0; i < q; i++) {
    cin >> num >> v;
    wakasagi[num] += v;
    pq.push(make_pair(wakasagi[num], -num));
    for (;;) {
      int b = -pq.top().second;
      int w = pq.top().first;
      if (wakasagi[b] == w) {
        cout << b << ' ' << w << endl;
        break;
      }
      pq.pop();
    }
  }
}

Error: 0

Fixed submission:

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

int main() {
  int q, num, v, max, maxnum;

  cin >> n >> q;
  int wakasagi[100000];
  priority_queue<pair<int, int>> pq;
  max = wakasagi[1];
  maxnum = 1;
  for (int i = 0; i < q; i++) {
    cin >> num >> v;
    wakasagi[num] += v;
    pq.push(make_pair(wakasagi[num], -num));
    for (;;) {
      int b = -pq.top().second;
      int w = pq.top().first;
      if (wakasagi[b] == w) {
        cout << b << ' ' << w << endl;
        break;
      }
      pq.pop();
    }
  }
}
Problem p00099 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define int long long
#define for1(i, n) for (int i = 1; i <= (n); i++)
#define mp make_pair
using namespace std;
set<pair<int, int>> s;
int a[1234567];
signed main() {
  int n, q;
  cin >> n >> q;
  for1(i, n) s.insert(mp(0, n - i));
  for1(valsqotch, q) {
    int id, v;
    cin >> id >> v;
    s.erase(s.find(mp(a[id], n - id)));
    a[id] += v;
    s.insert(mp(a[id], n - id));
    auto itr = s.end();
    itr--;
    cout << n - (*itr).second << ' ' << (*itr).first << endl;
  }
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long lint;
int main() {
  lint n, q;
  cin >> n >> q;
  lint l[1000010] = {0};
  vector<lint> v;
  for (lint i = 0; i < q; i++) {
    lint a, b;
    cin >> a >> b;
    if (find(v.begin(), v.end(), a) == v.end())
      v.push_back(a);
    l[a] += b;
    l[a] = max((lint)0, l[a]);
    lint num = 0, maxs = 0;
    sort(v.begin(), v.end());
    for (lint i = 0; i < v.size(); i++) {
      if (maxs < l[v[i]]) {
        num = v[i];
        maxs = l[v[i]];
      }
    }
    cout << num << ' ' << l[num] << endl;
  }
}
Problem p00099 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

using namespace std;

struct av {
  int a, v;
};

bool operator<(const av &dat1, const av &dat2) {
  if (dat1.v == dat2.v)
    return dat1.a > dat2.a;
  return dat1.v < dat2.v;
}

int main(void) {
  // read input
  int n, q;
  cin >> n >> q;
  vector<int> in_a(q, 0);
  vector<int> in_v(q, 0);
  vector<av> out(q);
  REP(i, q) { cin >> in_a[i] >> in_v[i]; }
  // calc
  int a_max = *max_element(in_a.begin(), in_a.end());
  int a_min = *min_element(in_a.begin(), in_a.end());
  vector<av> avlst(a_max + 1);
  REP(i, a_max + 1) {
    avlst[i].a = 0;
    avlst[i].v = 0;
  }
  // for each av
  int a = in_a[0];
  avlst[a].a = a;
  avlst[a].v = (in_v[0] > 0) ? in_v[0] : 0;
  out[0] = avlst[a];
  for (int i = 1; i < q; i++) {
    // sum
    a = in_a[i];
    avlst[a].a = a;
    avlst[a].v += in_v[i];
    if (avlst[a].v < 0)
      avlst[a].v = 0;
    // find max
    av av_max;
    if (in_v[i] > 0) {
      av_max = (out[i - 1] < avlst[a]) ? avlst[a] : out[i - 1];
    } else if (out[i - 1].a != a) {
      av_max = out[i - 1];
    } else {
      av_max.a = a_max + 1;
      av_max.v = -1;
      for (int j = a_min; j <= a_max; j++) {
        if (!avlst[j].a)
          continue;
        if (av_max < avlst[j])
          av_max = avlst[j];
      }
    }
    out[i] = av_max;
  }
  // write output
  REP(i, q) { cout << out[i].a << " " << out[i].v << endl; }
  return 0;
}

Error: TLE

Fixed submission:

// C++11
// 2.00sec
// 1.90sec
#include <algorithm>
#include <iostream>
#include <vector>

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

using namespace std;

struct av {
  int a, v;
};

bool operator<(const av &dat1, const av &dat2) {
  if (dat1.v == dat2.v)
    return dat1.a > dat2.a;
  return dat1.v < dat2.v;
}

int main(void) {
  // read input
  int n, q;
  cin >> n >> q;
  vector<int> in_a(q, 0);
  vector<int> in_v(q, 0);
  vector<av> out(q);
  REP(i, q) { cin >> in_a[i] >> in_v[i]; }
  // calc
  int a_max = *max_element(in_a.begin(), in_a.end());
  int a_min = *min_element(in_a.begin(), in_a.end());
  vector<av> avlst(a_max + 1);
  REP(i, a_max + 1) {
    avlst[i].a = 0;
    avlst[i].v = 0;
  }
  // for each av
  int a = in_a[0];
  avlst[a].a = a;
  avlst[a].v = (in_v[0] > 0) ? in_v[0] : 0;
  out[0] = avlst[a];
  for (int i = 1; i < q; i++) {
    // sum
    a = in_a[i];
    avlst[a].a = a;
    avlst[a].v += in_v[i];
    if (avlst[a].v < 0)
      avlst[a].v = 0;
    // find max
    av av_max;
    if (in_v[i] > 0) {
      av_max = (out[i - 1] < avlst[a]) ? avlst[a] : out[i - 1];
    } else {
      av_max = avlst[a];
      for (int j = 0; j < i; j++) {
        if (av_max < avlst[in_a[j]])
          av_max = avlst[in_a[j]];
      }
    }
    out[i] = av_max;
  }
  // write output
  REP(i, q) { cout << out[i].a << " " << out[i].v << endl; }
  return 0;
}
Problem p00099 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, event;
  cin >> n >> event;

  std::vector<int> possessionfish(n + 1, 0);
  std::vector<int>::iterator iter;
  int index, topNum;
  int fishing, num;
  cin >> num >> fishing;
  possessionfish[num] += fishing;
  cout << num << " " << fishing << endl;
  topNum = num;

  for (--event; event > 0; --event) {
    cin >> num >> fishing;
    possessionfish[num] += fishing;
    if (fishing > 0) {
      if (possessionfish[num] > possessionfish[topNum] ||
          topNum > num && possessionfish[num] == possessionfish[topNum])
        topNum = num;
    } else {
      if (topNum == num) {
        iter = std::max_element(possessionfish.begin(), possessionfish.end());
        index = std::distance(possessionfish.begin(), iter);
        topNum = index;
      }
    }
    cout << topNum << " " << possessionfish[topNum] << endl;
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, event;
  cin >> n >> event;

  std::vector<int> possessionfish(n + 1, 0);
  std::vector<int>::iterator iter;
  int index;

  for (int fishing, num; event > 0; --event) {
    cin >> num >> fishing;
    possessionfish[num] += fishing;
    iter = std::max_element(possessionfish.begin(), possessionfish.end());
    index = std::distance(possessionfish.begin(), iter);
    cout << index << " " << possessionfish[index] << endl;
  }
}
Problem p00099 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {

  int n, q;
  cin >> n >> q;

  vector<int> A(n, 0);
  priority_queue<pair<int, int>> Q;

  for (int i = 0; i < n; i++) {
    Q.push(make_pair(0, -i));
  }

  for (int i = 0; i < q; i++) {
    int a, v;
    cin >> a >> v;
    a--;
    A[a] += v;
    Q.push(make_pair(A[a], -a));

    pair<int, int> ans;
    while (1) {
      ans = Q.top();
      if (ans.first == A[-ans.second]) {
        break;
      } else {
        Q.pop();
      }
    }

    cout << -ans.second + 1 << ' ' << ans.first << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {

  int n, q;
  cin >> n >> q;

  vector<int> A(n, 0);
  priority_queue<pair<int, int>> Q;

  for (int i = 0; i < n; i++) {
    Q.push(make_pair(0, i));
  }

  for (int i = 0; i < q; i++) {
    int a, v;
    cin >> a >> v;
    a--;
    A[a] += v;
    Q.push(make_pair(v, a));

    pair<int, int> ans;
    while (1) {
      ans = Q.top();
      Q.pop();
      if (ans.first == A[ans.second])
        break;
    }

    cout << ans.second + 1 << ' ' << ans.first << endl;
  }
  return 0;
}
Problem p00099 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int date[2][2097152] = {};

void update(int x) {

  if (date[1][x * 2] >= date[1][x * 2 + 1]) {
    date[0][x] = date[0][x * 2];
    date[1][x] = date[1][x * 2];
  } else {
    date[0][x] = date[0][x * 2 + 1];
    date[1][x] = date[1][x * 2 + 1];
  }

  if (x != 1)
    update(x / 2);
}

int main() {

  int n, m, z;
  int a, b;

  cin >> n >> m;

  for (z = 1; z < n; z = z * 2) {
  }

  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    date[0][z + a - 1] = a;
    date[1][z + a - 1] += b;

    update((z + a - 1) / 2);

    cout << date[0][1] << " ";
    cout << date[1][1] << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int fishing[2][2097152] = {};

void max(int x, int y) {

  for (int k = y; k > x; k = k - 2) {
    if (fishing[0][k] == 0 && fishing[0][k - 1] == 0)
      break;
    if (fishing[1][k] == fishing[1][k - 1]) {
      if (fishing[0][k] < fishing[0][k - 1]) {
        fishing[0][k / 2] = fishing[0][k];
        fishing[1][k / 2] = fishing[1][k];
      } else {
        fishing[0][k / 2] = fishing[0][k - 1];
        fishing[1][k / 2] = fishing[1][k - 1];
      }
    } else if (fishing[1][k] > fishing[1][k - 1]) {
      fishing[0][k / 2] = fishing[0][k];
      fishing[1][k / 2] = fishing[1][k];
    } else if (fishing[1][k] < fishing[1][k - 1]) {
      fishing[0][k / 2] = fishing[0][k - 1];
      fishing[1][k / 2] = fishing[1][k - 1];
    }
  }

  if (x != 0)
    max(x / 2, x - 1);
}

int main() {

  int n, m, high;
  int a, b, z;

  cin >> n >> m;

  for (high = 1; high < n; high = high * 2) {
  }

  z = high * 2 - 1;

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

    for (int j = z; j > z - n; j--) {
      if (fishing[0][j] == a) {
        fishing[1][j] += b;
        break;
      } else if (fishing[0][j] == 0) {
        fishing[0][j] = a;
        fishing[1][j] = b;
        break;
      }
    }

    max(high, z);

    cout << fishing[0][1] << " ";
    cout << fishing[1][1] << endl;
  }
  return 0;
}
Problem p00099 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <queue>

#pragma warning(disable : 4996)

using namespace std;

int n, q, c[1000000], a, v;

int main() {
  scanf("%d", &n);
  scanf("%d", &q);

  priority_queue<pair<int, int>> que;

  for (int i = 0; i < q; i++) {
    scanf("%d", &a);
    scanf("%d", &v);

    c[a - 1] += v;
    que.push(make_pair(c[a - 1], -a));

    pair<int, int> maximum;

    while (true) {
      maximum = que.top();

      if (maximum.first != c[-maximum.second - 1]) {
        que.pop();
      } else {
        break;
      }
    }

    printf("%d %d\\n", -maximum.second, maximum.first);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <queue>

#pragma warning(disable : 4996)

using namespace std;

int n, q, c[1000000], a, v;

int main() {
  scanf("%d", &n);
  scanf("%d", &q);

  priority_queue<pair<int, int>> que;

  for (int i = 0; i < q; i++) {
    scanf("%d", &a);
    scanf("%d", &v);

    c[a - 1] += v;
    que.push(make_pair(c[a - 1], -a));

    pair<int, int> maximum;

    while (true) {
      maximum = que.top();

      if (maximum.first != c[-maximum.second + 1]) {
        que.pop();
      } else {
        break;
      }
    }

    printf("%d %d\\n", -maximum.second, maximum.first);
  }

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

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

typedef pair<int, int> P;

int main() {
  int a, n, q, v, m_a = 0;
  cin >> n >> q;
  vector<int> fish(n + 1, 0);
  priority_queue<P> pq;
  pq.push(P(1, 0));
  for (int i = 0; i < q; i++) {
    cin >> a >> v;
    fish[a] += v;
    pq.push(P(fish[a], -a));
    while (fish[-pq.top().second] != pq.top().first)
      pq.pop();
    cout << -pq.top().second << ' ' << pq.top().first << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

typedef pair<int, int> P;

int main() {
  int a, n, q, v, m_a = 0;
  cin >> n >> q;
  vector<int> fish(n, 0);
  priority_queue<P> pq;
  pq.push(P(1, 0));
  for (int i = 0; i < q; i++) {
    cin >> a >> v;
    fish[a] += v;
    pq.push(P(fish[a], -a));
    while (fish[-pq.top().second] != pq.top().first)
      pq.pop();
    cout << -pq.top().second << ' ' << pq.top().first << endl;
  }
  return 0;
}
Problem p00099 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int n, q;
int a, v;
int tt[1000001] = {0}, ten[1000001] = {0};
typedef pair<int, int> P;
priority_queue<P> qu;
int main(void) {
  int i, j, flg, max, min, n1, nn, ten1;
  P ppp;

  cin >> n >> q;

  max = -1;
  min = 1000000;

  for (i = 0; i < q; i++) {

    cin >> a >> v;

    ten[a] += v;

    qu.push(P(ten[a], a * -1));

    while (1) {
      ppp = qu.top();
      nn = ppp.second * -1;
      if (ten[nn] == ppp.first) {
        max = ppp.first;
        min = nn;
        break;
      }
      qu.pop();
    }

    cout << min << " " << max << endl;
  }

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int n, q;
int a, v;
int tt[100001] = {0}, ten[100001] = {0};
typedef pair<int, int> P;
priority_queue<P> qu;
int main(void) {
  int i, j, flg, max, min, n1, nn, ten1;
  P ppp;

  cin >> n >> q;

  max = -1;
  min = 1000000;
  flg = 1000000;

  for (i = 0; i < q; i++) {

    cin >> a >> v;

    if (flg < a)
      flg = a;

    ten[a] += v;

    //		qu.push(P(ten[a],a));

    /*		while(1){
                            ppp=qu.top();
                            nn=ppp.second;
                            if(ten[nn]==ppp.first){
                                    max=ppp.first;
                                    min=nn;
                                    break;
                            }
                            qu.pop();
                    }	*/

    max = -1;
    min = 1000000;

    for (j = 1; j <= n; j++) {
      if (max < ten[j]) {
        max = ten[j];
        min = j;
      }
    }

    cout << min << " " << max << endl;

    /*		for(i=1;j<=n1;j++){
                            if(max<ten[j]){
                                    max=ten[j];
                                    min=j;
                            }
                    }

                    cout<<min<<" "<<max<<endl;
                    */
  }

  // cout<<min<<" "<<max<<endl;

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

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

#define MAX_N 100000000

priority_queue<pair<int, int>> Q;
int d[MAX_N], n, s, x[MAX_N], y[MAX_N];

int main() {
  cin >> n >> s;
  Q.push(make_pair(0, -1000000000));
  for (int i = 0; i < s; i++) {
    cin >> x[i] >> y[i];
    d[x[i]] += y[i];
    Q.push(make_pair(d[x[i]], -x[i]));
    while (true) {
      pair<int, int> p = Q.top();
      if (p.first == d[-p.second]) {
        cout << -p.second << ' ' << p.first << endl;
        break;
      }
      Q.pop();
    }
  }
}

Error: TLE

Fixed submission:

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

#define MAX_N 100000000

priority_queue<pair<int, int>> Q;
int d[MAX_N], n, s, x[MAX_N], y[MAX_N];

int main() {
  cin >> n >> s;
  Q.push(make_pair(0, -1));
  for (int i = 0; i < s; i++) {
    cin >> x[i] >> y[i];
    d[x[i]] += y[i];
    Q.push(make_pair(d[x[i]], y[i]));
    while (true) {
      pair<int, int> p = Q.top();
      if (p.first == d[-p.second]) {
        cout << p.second << ' ' << p.first << endl;
        break;
      }
      Q.pop();
    }
  }
}