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

#include <bits/stdc++.h>
using namespace std;
priority_queue<pair<int, int>> Q;
int n, q, a, b, d[1000010];
int main() {
  cin >> n >> q;
  a = n;
  while (a--)
    Q.push(make_pair(0, a)), d[a] = 0;
  while (q--) {
    cin >> a >> b;
    a = n - a, d[a] += b;
    Q.push(make_pair(d[a], a));
    while (1) {
      a = Q.top().first, b = Q.top().second;
      if (d[b] == a) {
        cout << n - b << " " << a << endl;
        break;
      }
      Q.pop();
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int a[1000001] = {0};
int main() {
  int n, q, b, c;
  cin >> n >> q;
  for (int i = 0; i < q; i++) {
    cin >> b >> c;
    a[b] += c;
    int best = 0, set;
    for (int j = n; j >= 1; j--) {
      if (best <= a[j]) {
        best = a[j];
        set = j;
      }
    }
    cout << set << " " << a[set] << endl;
  }
  return 0;
}
Problem p00099 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>
#include <queue>

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

using namespace std;

int n[1000001];

int main() {
  memset(n, 0, sizeof(n));
  int num, q;
  cin >> num >> q;

  priority_queue<pair<int, int>> p;
  rep(i, q) {
    int a, v;
    cin >> a >> v;
    n[a - 1] += v;

    p.push(make_pair(n[a - 1], -(a - 1)));

    while (true) {
      int team = -p.top().second;
      if (n[team] == p.top().first) {
        cout << team + 1 << " " << p.top().first << endl;
        break;
      }
      p.pop();
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;

long long int n[1000001];
priority_queue<long long int> p;

int main() {
  memset(n, 0, sizeof(n));

  int num, _q;
  cin >> num >> _q;

  rep(i, _q) {
    int a, v;
    cin >> a >> v;

    n[a - 1] += v;
    p.push(n[a - 1]);

    long long int ans = p.top();

    vector<int> res;
    rep(j, 1000001) {
      if (n[j] == ans) {
        res.push_back(j);
      }
    }
    sort(res.begin(), res.end());
    cout << res[0] + 1 << " " << ans << endl;
  }
  return 0;
}
Problem p00099 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
using namespace std;
pair<int, int> tree[1000000 * 2 - 1];

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

    for (int i = 0; i < n * 2 - 1; i++)
      tree[i] = make_pair(0, 0);
    for (int i = 0; i < q; i++) {
      int a, v;
      cin >> a >> v;
      a--;
      int num = a + (n - 1);
      // cout<<num<<endl;
      tree[num].first += v;
      tree[num].second = a + 1;
      pair<int, int> base;
      while (true) {
        num = (num - 1) / 2;
        if (num * 2 + 2 < n * 2 - 1 &&
            (tree[num * 2 + 1].first < tree[num * 2 + 2].first ||
             (tree[num * 2 + 1].first == tree[num * 2 + 2].first &&
              tree[num * 2 + 1].second > tree[num * 2 + 2].second)))
          base = tree[num * 2 + 2];
        else
          base = tree[num * 2 + 1];
        tree[num] = base;
        if (num == 0)
          break;
      }
      cout << tree[0].second << " " << tree[0].first << endl;
      //	  output();
    }
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
using namespace std;

int main() {
  int n, q;
  for (; cin >> n >> q;) {
    pair<int, int> tree[n * 2 - 1];
    for (int i = 0; i < n * 2 - 1; i++)
      tree[i] = make_pair(0, 0);
    for (int i = 0; i < q; i++) {
      int a, v;
      cin >> a >> v;
      a--;
      int num = a + (n - 1);
      // cout<<num<<endl;
      tree[num].first += v;
      tree[num].second = a + 1;
      pair<int, int> base;
      while (true) {
        num = (num - 1) / 2;
        if (num * 2 + 2 < n * 2 - 1 &&
            (tree[num * 2 + 1].first < tree[num * 2 + 2].first ||
             (tree[num * 2 + 1].first == tree[num * 2 + 2].first &&
              tree[num * 2 + 1].second > tree[num * 2 + 2].second)))
          base = tree[num * 2 + 2];
        else
          base = tree[num * 2 + 1];
        tree[num] = base;
        if (num == 0)
          break;
      }
      cout << tree[0].second << " " << tree[0].first << endl;
      //	  output();
    }
  }
}
Problem p00099 (C++) — buggy submission, verdict: Time Limit Exceeded

// 55
#include <algorithm>
#include <iostream>

using namespace std;

const int N = 1048576;
const int B = N - 1;
int c[N];
int pa[N * 2];

void rec(int x) {
  if (x == 0)
    return;
  int p = (x - 1) / 2;
  pa[p] =
      (c[pa[p * 2 + 1]] >= c[pa[p * 2 + 2]]) ? pa[p * 2 + 1] : pa[p * 2 + 2];
  // if(pa[p]>=100){
  //   cout<<x<<' '<<p*2+1<<' '<<p*2+2<<endl;
  //   cout<<c[pa[p*2+1]]<<' '<<c[pa[p*2+2]]<<endl;
  //   cout<<pa[p*2+1]<<' '<<pa[p*2+2]<<endl;
  // }
  rec(p);
}

int main() {
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < N; i++) {
    pa[B + i] = i;
  }
  for (int i = B - 1; i >= 0; i--) {
    pa[i] = pa[i * 2 + 1];
  }
  while (q--) {
    int a, v;
    cin >> a >> v;
    c[a - 1] += v;
    rec(B + a - 1);
    cout << pa[0] + 1 << ' ' << c[pa[0]] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

// 55
#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  int n, q;
  cin >> n >> q;
  static int c[1000000];
  while (q--) {
    int a, v;
    cin >> a >> v;
    c[a - 1] += v;
    int x = max_element(c, c + n) - c;
    cout << x + 1 << ' ' << c[x] << endl;
  }
  return 0;
}
Problem p00099 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define mp make_pair
using namespace std;
typedef pair<int, int> pii;

class RMQ {
  int n;
  vector<pii> dat;

public:
  RMQ(int n_) { init(n_); }
  void init(int n_);
  void update(int k, int a);
  pii query(int a, int b, int k = 0, int l = 0, int r = 0);
};
void RMQ::init(int n_) {
  n = 1;
  while (n < n_)
    n *= 2;
  dat.resize(2 * n - 1);
  for (int i = 0; i < 2 * n - 1; i++) {
    if (i < n - 1)
      dat[i] = mp(-1e9, -1e9);
    else
      dat[i] = mp(0, -i + n - 1);
  }
}

void RMQ::update(int k, int a) {
  k += n - 1;
  dat[k].first += a;
  while (k > 0) {
    k = (k - 1) / 2;
    dat[k] = max(dat[2 * k + 1], dat[2 * k + 2]);
  }
}

pii RMQ::query(int a, int b, int k, int l, int r) {
  if (r <= l)
    r = n;
  if (r <= a || b <= l)
    return mp(-1e9, -1e9);
  if (a <= l && r <= b)
    return dat[k];
  pii vl = query(a, b, 2 * k + 1, l, (r + l) / 2);
  pii vr = query(a, b, 2 * k + 2, (r + l) / 2, r);
  return max(vl, vr);
}
int main(int argc, char *argv[]) {
  int n, p, a, v;
  cin >> n >> p;
  RMQ segtree(n);
  for (int i = 0; i < p; i++) {
    scanf("%d %d", &a, &v);
    segtree.update(a - 1, v);
    pii ans = segtree.query(0, n);
    printf("%d %d\\n", -ans.second + 1, ans.first);
  }

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define mp make_pair
using namespace std;
typedef pair<int, int> pii;

class RMQ {
  int n;
  vector<pii> dat;

public:
  RMQ(int n_) { init(n_); }
  void init(int n_);
  void update(int k, int a);
  pii query(int a, int b, int k = 0, int l = 0, int r = 0);
};
void RMQ::init(int n_) {
  n = 1;
  while (n < n_)
    n *= 2;
  dat.resize(2 * n - 1);
  for (int i = 0; i < 2 * n; i++) {
    if (n_ + n - 1 <= i || i < n - 1)
      dat[i] = mp(-1e9, -1e9);
    else
      dat[i] = mp(0, -i + n - 1);
  }
}

void RMQ::update(int k, int a) {
  k += n - 1;
  dat[k].first += a;
  while (k > 0) {
    k = (k - 1) / 2;
    dat[k] = max(dat[2 * k + 1], dat[2 * k + 2]);
  }
}

pii RMQ::query(int a, int b, int k, int l, int r) {
  if (r <= l)
    r = n;
  if (r <= a || b <= l)
    return mp(-1e9, -1e9);
  if (a <= l && r <= b)
    return dat[k];
  pii vl = query(a, b, 2 * k + 1, l, (r + l) / 2);
  pii vr = query(a, b, 2 * k + 2, (r + l) / 2, r);
  return max(vl, vr);
}
int main(int argc, char *argv[]) {
  int n, p, a, v;
  cin >> n >> p;
  RMQ segtree(n);
  for (int i = 0; i < p; i++) {
    scanf("%d %d", &a, &v);
    // segtree.update(a - 1, v);
    // pii ans = segtree.query(0, n - 1);
    // printf("%d %d\\n", -ans.second + 1, ans.first);
  }

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

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

int main() {
  int n, q;
  while (cin >> n >> q) {
    vector<int> cnt(n + 1, 0);
    priority_queue<pair<int, int>> p;
    for (int i = 0; i < q; ++i) {
      pair<int, int> a;
      cin >> a.second >> a.first;
      cnt[a.second] += a.first;
      a.first = cnt[a.second];
      a.second = -a.second;
      p.push(a);
      while (1) {
        pair<int, int> b;
        b = p.top();
        p.pop();
        if (b.first == cnt[-b.second]) {
          cout << -b.second << " " << b.first << endl;
          p.push(b);
          break;
        }
      }
    }
  }

  return 0;
}

Error: MLE

Fixed submission:

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

struct Data {
  Data() : id(0), cnt(0), prev(NULL), next(NULL) {}
  int id;
  int cnt;
  Data *prev;
  Data *next;
};

int main() {
  int n, q;
  while (cin >> n >> q) {
    vector<Data *> total(100 * q + 1, NULL);
    vector<Data> p(100000, Data());
    vector<Data *> acc(n + 1, NULL);
    int sec = 0;
    acc[1] = &p[sec];
    p[sec].id = 1;
    ++sec;
    total[0] = acc[1];

    int high = 0;
    for (int i = 0; i < q; ++i) {
      int a, v;
      cin >> a >> v;
      if (acc[a] == NULL) {
        acc[a] = &p[sec];
        acc[a]->id = a;
        ++sec;
      }
      Data *b = acc[a];
      if (total[b->cnt] == b) {
        total[b->cnt] = b->next;
      }
      b->cnt += v;
      Data *pp = b->prev;
      Data *pn = b->next;
      if (pp != NULL)
        pp->next = pn;
      if (pn != NULL)
        pn->prev = pp;
      b->prev = b->next = NULL;
      Data *s = total[b->cnt];
      if (s == NULL) {
        total[b->cnt] = b;
      } else {
        while (s->next != NULL && s->id < b->id)
          s = s->next;
        if (s->id < b->id) {
          s->next = b;
          b->prev = s;
        } else {
          b->next = s;
          b->prev = s->prev;
          s->prev = b;
          if (b->prev == NULL) {
            total[b->cnt] = b;
          }
        }
      }
      if (v > 0) {
        high = max(high, b->cnt);
      } else {
        while (total[high] == NULL)
          --high;
      }
      cout << total[high]->id << " " << total[high]->cnt << endl;
    }
  }

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

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

const int MAX = 10000100;

#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define all(a) (a).begin(), (a).end()
#define ll long long int
#define gcd(a, b) __gcd(a, b)
#define pb(a) push_back(a)
int GCD(int a, int b) {
  if (!b)
    return a;
  return gcd(b, a % b);
}
int lcm(int a, int b) { return a * b / gcd(a, b); }
typedef pair<int, int> pii;
int main(void) {
  int n, m;
  cin >> n >> m;
  map<int, int> mp;
  priority_queue<pii> q;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    mp[a] += b;
    q.push(make_pair(mp[a], -a));
    while (true) {
      pii p = q.top();
      if (mp[-p.second] == p.first) {
        cout << -p.second << " " << p.first << endl;
        break;
      }
      q.pop();
    }
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

const int MAX = 10000100;

#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define all(a) (a).begin(), (a).end()
#define ll long long int
#define gcd(a, b) __gcd(a, b)
#define pb(a) push_back(a)
int GCD(int a, int b) {
  if (!b)
    return a;
  return gcd(b, a % b);
}
int lcm(int a, int b) { return a * b / gcd(a, b); }

int main(void) {
  int n, q;
  cin >> n >> q;
  vector<int> sum(n, 0);
  int a, v;
  int maxa, maxv;
  maxv = maxa = -1 * MAX;

  rep(i, q) {
    cin >> a >> v;
    sum[--a] += v;
    maxv = -1 * (1e8);
    rep(j, n) {
      if (sum[j] > maxv) {
        maxa = j + 1;
        maxv = sum[j];
      }
    }
    cout << maxa << " " << maxv << endl;
  }
}
Problem p00099 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define P pair<int, int>
using namespace std;

P seg[2100000]{};
void kousin(int a) {
  while (a) {
    a = (a - 1) / 2;
    if (seg[a * 2 + 2].first > seg[a * 2 + 1].first)
      seg[a] = seg[a * 2 + 2];
    else
      seg[a] = seg[a * 2 + 1];
  }
}
int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  int n = 1;
  while (n < a)
    n <<= 1;
  for (int c = n - 1; c < n * 2 - 1; c++)
    seg[c] = P(0, c - n + 2);
  for (int d = 0; d < b; d++) {
    int e, f;
    scanf("%d%d", &e, &f);
    seg[n + e - 2].first += f;
    kousin(n + e - 2);
    printf("%d %d\\n", seg[0].second, seg[0].first);
  }
}

Error: 0

Fixed submission:

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

signed main() {
  int a, b;
  cin >> a >> b;
  vector<int> c(b);
  set<int> s;
  int x = 0, y = 0;
  for (int d = 0; d < b; d++) {
    int e, f;
    cin >> e >> f;
    e--;
    c[e] += f;
    s.insert(e);
    if (f < 0) {
      x = y = 0;
      for (auto i = s.begin(); i != s.end(); i++) {
        if (x < c[*i]) {
          x = c[*i];
          y = *i;
        }
      }
    } else {
      if (x < c[e] || (x == c[e] && e < y)) {
        x = c[e];
        y = e;
      }
    }
    cout << y + 1 << " " << x << endl;
  }
}
Problem p00099 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;

typedef pair<int, int> P;
priority_queue<P> que;

int data[1111111];

int solve(int a, int b) {

  data[a] += b;
  que.push(P(data[a], -a));

  for (;;) {
    a = -que.top().S;
    b = que.top().F;

    if (b == data[a])
      break;
    que.pop();
  }

  cout << a << " " << b << endl;
}

int main() {

  int n, q, a, b;
  cin >> n >> q;

  for (; q--;) {
    cin >> a >> b;
    solve(a, b);
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {

  int n, q;
  int z[1000001] = {0};
  int a, b;
  int k, ans;

  cin >> n >> q;

  for (int i = 0; i < q; i++) {
    cin >> a >> b;
    z[a] += b;
    ans = -1;
    k = -1;
    for (int i = 1; i <= n; i++) {
      if (ans < z[i]) {
        ans = z[i];
        k = i;
      }
    }

    cout << k << " " << ans << endl;
  }
}
Problem p00099 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define INF 999999999

template <class T> class segtree {
private:
  vector<T> dat;
  int _size; // the number of leaves
  T _init;

public:
  segtree(int __size = 0, T init = numeric_limits<T>::max())
      : _size(__size), _init(init), dat(4 * __size, init) {
    if (__size == 0)
      return;
    int x = 1;
    while (x < _size)
      x *= 2;
    _size = x;
  }

  void update(int m, T x) {
    int i = m + _size;
    dat[i].second = x.second;
    dat[i].first += x.first;
    while (i != 1) {
      dat[i / 2] = max(dat[i], dat[i ^ 1]);
      i /= 2;
    }
  }

  // call find(s,t)
  T find(int s, int t, int num = 1, int a = 0, int b = -1) {
    if (b == -1)
      b = _size - 1; // I couldn't "int b=_size".
    if (b < s || t < a)
      return _init;
    if (s <= a && b <= t)
      return dat[num];
    return max(find(s, t, num * 2, a, (a + b) / 2),
               find(s, t, num * 2 + 1, (a + b) / 2 + 1, b));
  }
  int size() { return _size; }
};

int main() {
  int n, q;
  cin >> n >> q;
  segtree<pii> st(n, pii(0, 0)); // 100 datas
  rep(i, n) { st.update(i, pii(0, -1 * i)); }
  rep(i, q) {
    int a, v;
    cin >> a >> v;
    a--;
    st.update(a, pii(v, -1 * a));
    cout << -1 * st.find(0, n).second + 1 << " " << st.find(0, n).first << endl;
  }
}

Error: -11

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define INF 999999999

template <class T> class segtree {
private:
  vector<T> dat;
  int _size; // the number of leaves
  T _init;

public:
  segtree(int __size = 0, T init = numeric_limits<T>::max())
      : _size(__size), _init(init), dat(4 * __size, init) {
    if (__size == 0)
      return;
    int x = 1;
    while (x < _size)
      x *= 2;
    _size = x;
  }

  void update(int m, T x) {
    int i = m + _size;
    dat[i].second = x.second;
    dat[i].first += x.first;
    while (i != 1) {
      dat[i / 2] = max(dat[i], dat[i ^ 1]);
      i /= 2;
    }
  }

  // call find(s,t)
  T find(int s, int t, int num = 1, int a = 0, int b = -1) {
    if (b == -1)
      b = _size - 1; // I couldn't "int b=_size".
    //        if(b<s||t<a)return _init;
    if (s <= a && b <= t)
      return dat[num];
    return max(find(s, t, num * 2, a, (a + b) / 2),
               find(s, t, num * 2 + 1, (a + b) / 2 + 1, b));
  }
  int size() { return _size; }
};

int main() {
  int n, q;
  cin >> n >> q;
  segtree<pii> st(n, pii(0, 0)); // 100 datas
  rep(i, n) { st.update(i, pii(0, -1 * i)); }
  rep(i, q) {
    int a, v;
    cin >> a >> v;
    a--;
    st.update(a, pii(v, -1 * a));
    cout << -1 * st.find(0, n - 1).second + 1 << " " << st.find(0, n).first
         << endl;
  }
}
Problem p00099 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define REP(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep(i, n) REP(i, 0, (n))
#define pb(n) push_back(n)
#define mp(n, m) make_pair(n, m)
#define all(r) r.begin(), r.end()
#define fi first
#define se second
#define println(X) cout << X << endl;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;

const int MAX_N = 1 << 20;

int n;
pii dat[2 * MAX_N - 1];
void init(int n_) {
  n = 1;
  while (n < n_)
    n *= 2;
  for (int i = 0; i < 2 * n - 1; i++) {
    dat[i].fi = 0;
    dat[i].se = -(i - n + 2);
  }
}

void update(int k, int add) {
  k += n - 1;
  dat[k].fi += add;
  while (k > 0) {
    k = (k - 1) / 2;
    dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]);
  }
}

pii query(int a, int b, int k, int l, int r) {
  if (r <= a || b <= l)
    return pii(0, 0);
  if (a <= l && r <= b)
    return dat[k];
  else {
    pii vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    pii vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return min(vl, vr);
  }
}

int main() {
  int q;
  cin >> n >> q;
  init(n);
  int m, add;
  pii out;
  rep(i, q) {
    cin >> m >> add;
    m--;
    update(m, add);
    out = query(0, n, 0, 0, n);
    println(-out.se << " " << out.fi);
    // cout<<dat[0].se * -1 << " "<<dat[0].fi<<endl;
    //  for(int i = 0; i < n; i++){
    //  	cout<<" ("<<-dat[i+n-1].se<<", "<<dat[i+n-1].se<<")";
    //  }
    //  cout<<endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define pb(n) push_back(n)
#define mp(n, m) make_pair(n, m)
#define fi first
#define se second
#define all(r) (r).begin(), (r).end()

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int IMAX = ((1 << 30) - 1) * 2 + 1;
const double EPS = 1e-10;
// int mod=1000000007;

int main() {
  int n, q;
  cin >> n >> q;
  vector<pii> v(n, pii(0, 0));
  vector<pii> v2;
  rep(i, n) { v[i].se = i + 1; }
  int a, b;
  rep(i, q) {
    cin >> a >> b;
    v[a - 1].fi -= b;
    v2 = v;
    sort(all(v2));
    cout << v2[0].se << " " << v2[0].fi * (-1) << endl;
  }
}
Problem p00099 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)

#define PB push_back
#define INF INT_MAX / 3
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) a > b ? a : b

typedef long long int ll;

using namespace std;
pair<int, int> tree[3000001];
int n, q;

pair<int, int> pmax(pair<int, int> a, pair<int, int> b) {
  pair<int, int> ret = MAX(a, b);
  if (a.first == b.first) {
    ret.second = min(a.second, b.second);
  }
  return ret;
}

void init(int k, int l, int r) {
  if (r - l == 1)
    tree[k] = tree[l];
  else {
    int chl = 2 * k + 1, chr = 2 * k + 2;
    int m = (int)((l + r) / 2);
    init(chl, l, m);
    init(chr, m, r);
    tree[k] = pmax(tree[chl], tree[chr]);
  }
}

void update(int k, int a) {
  k += n;
  tree[k].first += a;
  while (k > 0) {
    k = (k - 1) / 2;
    tree[k] = pmax(tree[2 * k + 1], tree[2 * k + 2]);
  }
}

int main() {
  // pair<int,int> ma(-100000000,-1);
  cin >> n >> q;
  REP(i, 2 * n) tree[n + i] = pair<int, int>(0, 0);
  REP(i, n) { tree[n + i].second = i + 1; }
  vector<pair<int, int>> ar(n);
  vector<bool> u(q, false);
  REP(i, q) {
    int a, v;
    cin >> a >> v;
    update(a - 1, v);
    cout << tree[0].second << " " << tree[0].first << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)

#define PB push_back
#define INF INT_MAX / 3
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) a > b ? a : b

typedef long long int ll;

using namespace std;
pair<int, int> tree[2000001];
int n, q;

pair<int, int> pmax(pair<int, int> a, pair<int, int> b) {
  pair<int, int> ret = MAX(a, b);
  if (a.first == b.first) {
    ret.second = min(a.second, b.second);
  }
  return ret;
}

void init(int k, int l, int r) {
  if (r - l == 1)
    tree[k] = tree[l];
  else {
    int chl = 2 * k + 1, chr = 2 * k + 2;
    int m = (int)((l + r) / 2);
    init(chl, l, m);
    init(chr, m, r);
    tree[k] = pmax(tree[chl], tree[chr]);
  }
}

void update(int k, int a) {
  k += n;
  tree[k].first += a;
  while (k > 0) {
    k = (k - 1) / 2;
    tree[k] = pmax(tree[2 * k + 1], tree[2 * k + 2]);
  }
}

int main() {
  // pair<int,int> ma(-100000000,-1);
  cin >> n >> q;
  REP(i, 2 * n) tree[n + i] = pair<int, int>(0, 0);
  REP(i, n) { tree[n + i].second = i + 1; }
  vector<pair<int, int>> ar(n);
  vector<bool> u(q, false);
  REP(i, q) {
    int a, v;
    cin >> a >> v;
    update(a - 1, v);
    cout << tree[0].second << " " << tree[0].first << endl;
  }
  return 0;
}