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

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

typedef long long ll;
#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

int main() {
  int n;
  cin >> n;
  int data[200][200];
  rep(i, n) rep(j, n) { cin >> data[i][j]; }

  int maxi = -1000000000;
  rep(i, n) {
    rep(j, n) {
      int dp[200][200] = {};
      for (int k = i; k < n; k++) {
        for (int l = j; l < n; l++) {
          dp[k][l] = (k - 1 >= i) * dp[k - 1][l] + (l - 1 >= j) * dp[k][l - 1] -
                     (k - 1 >= i && l - 1 >= j) * dp[k - 1][l - 1] + data[k][l];

          maxi = max(maxi, dp[k][l]);
        }
      }
    }
  }
  cout << maxi << endl;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

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

int main() {
  int n;
  while (cin >> n) {
    if (n == 0)
      break;
    int data[101][101];
    rep(i, n) {
      rep(j, n) { cin >> data[i][j]; }
    }

    int ans = -999999999;

    rep(i, n) {
      rep(j, n) {
        int dp[101][101];
        rep(k, 101) rep(l, 101) dp[k][l] = -999999999;
        dp[i][j] = data[i][j];

        for (int k = i; k < n; k++) {
          for (int l = j; l < n; l++) {
            if (l + 1 < n) {
              int right = 0;
              for (int loop = i; loop <= k; loop++)
                right += data[loop][l + 1];
              dp[k][l + 1] = dp[k][l] + right;
            }
            if (k + 1 < n) {
              int under = 0;
              for (int loop = j; loop <= l; loop++)
                under += data[k + 1][loop];
              dp[k + 1][l] = dp[k][l] + under;
            }
            if (l + 1 < n && k + 1 < n)
              dp[k + 1][l + 1] =
                  dp[k][l + 1] + dp[k + 1][l] - dp[k][l] + data[k + 1][l + 1];
          }
        }

        for (int k = i; k < n; k++)
          for (int l = j; l < n; l++) {
            ans = max(ans, dp[k][l]);
          }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00098 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#define N 100

int sum(int top, int under, int left, int right, int a[N][N], int temp);

int main(int argc, const char *argv[]) {
  int n = 0;
  scanf("%d", &n);
  int a[N][N] = {0};

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  /*---------------*/

  int max = a[0][0];

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = i; k < n; k++) {
        int l = j;
        int temp = 0;
        while (l < n) {
          temp = sum(i, k, j, l, a, temp);
          if (temp > max) {
            max = temp;
          } else if (temp < 0) {
            l = n;
          }
          l++;
        }
      }
    }
  }

  /*---------------*/
  printf("%d\\n", max);
}

int sum(int top, int under, int left, int right, int a[N][N], int temp) {
  // int temp=0;
  for (int i = top; i <= under; i++) {
    temp += a[i][right];
  }
  return temp;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
#include <vector>

using namespace std;

vector<string> split(string s, string c) {
  vector<string> ret;
  for (int i = 0, n; i <= s.length(); i = n + 1) {
    n = s.find_first_of(c, i);
    if (n == string::npos) {
      n = s.length();
    }
    string tmp = s.substr(i, n - i);
    ret.push_back(tmp);
  }
  return ret;
}

int main() {
  int n;
  cin >> n;
  cin.ignore();

  long data[n][n];

  for (int i = 0; i < n; i++) {
    string strRow = "";
    getline(cin, strRow);
    vector<string> row = split(strRow, " ");
    for (int j = 0; j < row.size(); j++) {
      data[i][j] = stoi(row[j]);
    }
  }

  long max = -1000000000000;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = i; k < n; k++) {
        for (int l = j; l < n; l++) {
          long sum = 0;
          for (int a = i; a <= k; a++) {
            for (int b = j; b <= l; b++) {
              sum += data[a][b];
            }
          }
          max = sum > max ? sum : max;
        }
      }
    }
  }

  cout << max << endl;
}
Problem p00098 (C++) — buggy submission, verdict: Time Limit Exceeded



#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#define N 100

int sum(int top, int under, int left, int right, int a[N][N], int temp);
// int search(int top, int under, int left, int right, int max, int a[N][N], int
// n);

int main(int argc, const char *argv[]) {
  int n = 0;
  scanf("%d", &n);
  int a[N][N] = {0};

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  /*---------------*/

  int max = a[0][0];

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = i; k < n; k++) {
        int l = j;
        int temp = 0;
        while (l < n) {
          temp = sum(i, k, j, l, a, temp);
          if (temp > max) {
            max = temp;
          } else if (temp < 0) {
            l = n;
          }
          l++;
        }
      }
    }
  }

  /*---------------*/
  printf("%d\\n", max);
}

int sum(int top, int under, int left, int right, int a[N][N], int temp) {
  // int temp=0;
  for (int i = top; i <= under; i++) {
    // for(int j=left; j<=right; j++){
    temp += a[i][right];
    //}
  }
  // printf("%d,top:%d,under:%d,left:%d,right:%d\\n",temp,top,under,left,right);
  return temp;
}

Error: TLE

Fixed submission:

//
//  main.cpp
//  Maximum Sum Sequence II
//
//  Created by 八代 光平 on 13/04/24.
//  Copyright (c) 2013年 八代 光平. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#define N 100

int sum(int top, int under, int left, int right, int a[N][N]);
int search(int top, int under, int left, int right, int max, int a[N][N],
           int n);

int main(int argc, const char *argv[]) {
  int n = 0;
  scanf("%d", &n);
  int a[N][N] = {0};

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  /*---------------*/

  int max = a[0][0];

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = i; k < n; k++) {
        int l = j;
        int temp = 0;
        while (l < n) {
          temp = sum(i, k, j, l, a);
          if (temp > max) {
            max = temp;
          } else if (temp < 0) {
            l = n;
          }
          l++;
        }
      }
    }
  }

  /*---------------*/
  printf("%d\\n", max);
}

int sum(int top, int under, int left, int right, int a[N][N]) {
  int temp = 0;
  for (int i = top; i <= under; i++) {
    for (int j = left; j <= right; j++) {
      temp += a[i][j];
    }
  }
  // printf("%d,top:%d,under:%d,left:%d,right:%d\\n",temp,top,under,left,right);
  return temp;
}
Problem p00098 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <cstdio>
#include <iostream>

using namespace std;

int DP[101][101][101]; // DP[i][j][k] : (???,
                       // ???)???????????¨?????????*??????????????¢??????

int main() {

  int n, ans;

  cin >> n;

  int dummy;

  for (int i = 0; i < 101; i++) {
    for (int j = 0; j < 101; j++) {
      for (int k = 0; k < 101; k++) {
        DP[i][j][k] = -(1 << 30);
      }
    }
  }

  ans = -(1 << 30);

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> dummy;
      DP[i][j][1] = dummy;
      if (DP[i][j][1] > ans) {
        ans = DP[i][j][1];
      }
    }
  }

  for (int y = 2; y <= n; y++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j <= n - y; j++) {
        DP[i][j][y] = DP[i][j][y - 1] + DP[i][j + y - 1][1];
        if (DP[i][j][y] > ans) {
          ans = DP[i][j][y];
        }
      }
    }
  }

  int sum;

  for (int x = 2; x <= n; x++) {
    for (int y = 1; y <= n; y++) {
      for (int j = 0; j <= n - y; j++) {
        for (int i = 0; i <= n - x; i++) {
          sum = 0;
          for (int k = 0; k < x; k++) {
            sum += DP[i + k][j][y];
          }
          if (sum > ans) {
            ans = sum;
          }
        }
      }
    }
  }

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

Error: MLE

Fixed submission:

#include <cstdio>
#include <iostream>

using namespace std;

int DP[101][101][101][101]; // DP[i][j][k][l] : (???,
                            // ???)???????????¨?????????*??????????????¢??????

int main() {

  int n, ans;

  cin >> n;

  int dummy;

  for (int i = 0; i < 101; i++) {
    for (int j = 0; j < 101; j++) {
      for (int k = 0; k < 101; k++) {
        for (int l = 0; l < 101; l++) {
          DP[i][j][k][l] = -(1 << 30);
        }
      }
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> dummy;
      DP[i][j][1][1] = dummy;
    }
  }

  for (int y = 2; y <= n; y++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j <= n - y; j++) {
        DP[i][j][1][y] = DP[i][j][1][y - 1] + DP[i][j + y - 1][1][1];
      }
    }
  }

  for (int x = 2; x <= n; x++) {
    for (int y = 1; y <= n; y++) {
      for (int i = 0; i <= n - x; i++) {
        for (int j = 0; j <= n - y; j++) {
          DP[i][j][x][y] = DP[i][j][x - 1][y] + DP[i + x - 1][j][1][y];
        }
      }
    }
  }

  ans = -(1 << 30);

  // printf("\\n");

  for (int x = 1; x <= n; x++) {
    for (int y = 1; y <= n; y++) {
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
          if (ans < DP[i][j][x][y]) {
            ans = DP[i][j][x][y];
          }
          // printf("%d ", DP[i][j][x][y]);
        }
        // printf("\\n");
      }
      // printf("\\n");
    }
  }
  printf("%d\\n", ans);
  return 0;
}
Problem p00099 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repb(i, a, b) for (int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
// #define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int d[1000001];
set<pii> st;

signed main() {
  int n, q;
  cin >> n >> q;
  rep(i, 0, n) { st.insert(make_pair(0, i)); }
  rep(i, 0, q) {
    int a, v;
    cin >> a >> v;
    a--;
    st.erase(st.find(make_pair(d[a], a)));
    d[a] -= v;
    st.insert(make_pair(d[a], a));
    set<pii>::iterator it = st.begin();
    cout << it->se + 1 << " " << -it->fi << endl;
  }
}

Error: MLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repb(i, a, b) for (int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int d[1000001];
set<pii> st;

signed main() {
  int n, q;
  cin >> n >> q;
  rep(i, 0, n) { st.insert(make_pair(0, i)); }
  rep(i, 0, q) {
    int a, v;
    cin >> a >> v;
    a--;
    st.erase(st.find(make_pair(d[a], a)));
    d[a] -= v;
    st.insert(make_pair(d[a], a));
    set<pii>::iterator it = st.begin();
    cout << it->se + 1 << " " << -it->fi << endl;
  }
}
Problem p00099 (C++) — buggy submission, verdict: Time Limit Exceeded

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

struct node {
  int a, b;
};
bool operator<(node a, node b) {
  if (a.a == b.a)
    return a.b > b.b;
  return a.a < b.a;
}

int cnt[1000001];
int main() {
  priority_queue<node> que;
  int n, q;
  scanf("%d%d", &n, &q);
  rep(i, q) {
    int a, v;
    scanf("%d%d", &a, &v);
    cnt[a] += v;
    que.push({cnt[a], a});
    for (; cnt[que.top().b] != que.top().a; que.pop())
      ;
    printf("%d %d\\n", que.top().b, que.top().a);
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef pair<int, int> P;

map<int, int> mp;
int main() {
  int n, q;
  cin >> n >> q;
  rep(i, q) {
    int a, v;
    cin >> a >> v;
    mp[a] += v;
    vector<P> V;
    for (P i : mp)
      V.push_back(i);
    stable_sort(V.begin(), V.end(),
                [](P a, P b) { return a.second > b.second; });
    cout << V[0].first << ' ' << V[0].second << endl;
  }
}
Problem p00099 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

typedef pair<int, int> P;

int main() {
  int n, q, a, v, f[1000001] = {};

  priority_queue<P> pq;

  cin >> n >> q;

  for (int i = 0; i < q; i++) {
    if (cin >> a >> v)
      ;
    else
      break;
    f[a] += v;
    pq.push(P(f[a], -a));
    for (;;) {
      int A = pq.top().first;
      int B = -pq.top().second;

      if (f[B] == A) {
        cout << B << " " << A << endl;
        break;
      } else {
        pq.pop();
      }
    }
  }

  return 0;
}

Error: MLE

Fixed submission:

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

typedef pair<int, int> P;

int main() {
  int n, q, a, v, f[1000001] = {};

  priority_queue<P> pq;

  for (;;) {
    cin >> a >> v;
    f[a] += v;
    pq.push(P(f[a], -a));
    for (;;) {
      int A = pq.top().first;
      int B = -pq.top().second;

      if (f[B] == A) {
        cout << B << " " << A << endl;
        break;
      } else {
        pq.pop();
      }
    }
  }

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

#include <iostream>
using namespace std;

int main() {
  int n, q;
  int a, v;
  int array[1000001] = {};
  int index, max_num;
  cin >> n >> q;
  index = n + 1;
  max_num = 0;

  while (cin >> a >> v) {
    array[a] += v;
    if (v > 0) {
      if ((array[a] > max_num) || ((array[a] == max_num) && a < index)) {
        index = a;
        max_num = array[a];
      }
    } else {
      if (a == index) {
        index = n + 1;
        max_num = 0;
        for (int i = 1; i <= n; i++) {
          if (array[i] > max_num) {
            index = i;
            max_num = array[i];
          }
        }
      }
    }
    cout << index << " " << max_num << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, q;
  int a, v;
  vector<int> vec;
  cin >> n >> q;
  vec.resize(n);
  fill(vec.begin(), vec.end(), 0);
  while (cin >> a >> v) {
    vec[a - 1] += v;
    auto itr = max_element(vec.begin(), vec.end());
    int index = distance(vec.begin(), itr) + 1;
    cout << index << " " << *itr << endl;
  }
  return 0;
}
Problem p00099 (C++) — buggy submission, verdict: Runtime Error

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

using P = pair<int, int>;

int n;
int q;
P seg[3000000];

int parent(int c) { return (c - 1) / 2; }

int nodeN(int i) { return n + i - 1; }

int otherC(int node) {
  return (2 * parent(node) + 1) < node ? node - 1 : node + 1;
}

void update(int c1) {
  int c2 = otherC(c1);
  int p = parent(c1);
  while (c1 != 0) {
    if (seg[c1].second == seg[c2].second) {
      seg[p].first = min(seg[c1].first, seg[c2].first);
      seg[p].second = seg[c1].second;
    } else if (seg[c1].second > seg[c2].second) {
      seg[p] = seg[c1];
    } else {
      seg[p] = seg[c2];
    }
    c1 = p;
    c2 = otherC(c1);
    p = parent(c1);
  }
}

int main() {
  cin >> n >> q;
  n = (int)pow(2, ceil(log2(n)));
  for (int i = 0; i < q; i++) {
    int a, v;
    cin >> a >> v;
    a--;
    int node = nodeN(a);
    seg[node].first = a + 1;
    seg[node].second += v;
    update(node);
    cout << seg[0].first << ' ' << seg[0].second << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

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

using P = pair<int, int>;

int n;
int q;
P seg[2000000];

int parent(int c) { return (c - 1) / 2; }

int nodeN(int i) { return n + i - 1; }

int otherC(int node) {
  return (2 * parent(node) + 1) < node ? node - 1 : node + 1;
}

void update(int c1) {
  int c2 = otherC(c1);
  int p = parent(c1);
  while (c1 > 0 && c2 > 0) {
    if (seg[c1].second == seg[c2].second) {
      seg[p].first = min(seg[c1].first, seg[c2].first);
      seg[p].second = seg[c1].second;
    } else if (seg[c1].second > seg[c2].second) {
      seg[p] = seg[c1];
    } else {
      seg[p] = seg[c2];
    }
    c1 = p;
    c2 = otherC(c1);
    p = parent(c1);
  }
}

int main() {
  cin >> n >> q;
  n = (int)pow(2, ceil(log2(n)));
  for (int i = 0; i < q; i++) {
    int a, v;
    cin >> a >> v;
    a--;
    int node = nodeN(a);
    seg[node].first = a + 1;
    seg[node].second += v;
    update(node);
    cout << seg[0].first << ' ' << seg[0].second << endl;
  }

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

#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i, j) for (int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for (int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef pair<int, int> P;
const int MAX_N = 2000010;

int N, Q;
P v[2 * MAX_N - 1];

void init(int _n) {
  N = 1;
  while (N < _n)
    N *= 2;
  REP(i, 2 * N - 1) v[i] = P(0, 0);
  REP(i, _n) v[i + N - 1].second = i * -1;
}

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

int main() {
  cin >> N >> Q;
  init(N);
  REP(i, Q) {
    int a, b;
    cin >> a >> b;
    update(a - 1, b);
    cout << v[0].second * -1 + 1 << " " << v[0].first << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i, j) for (int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for (int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef pair<int, int> P;
const int MAX_N = 1000010;

int N, Q;
P v[2 * MAX_N - 1];

void init(int _n) {
  N = 1;
  while (N < _n)
    N *= 2;
  REP(i, 2 * N - 1) v[i] = P(0, 0);
  REP(i, _n) v[i + N - 1].second = i * -1;
}

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

int main() {
  cin >> N >> Q;
  init(N);
  REP(i, Q) {
    int a, b;
    cin >> a >> b;
    update(a - 1, b);
    cout << v[0].second * -1 + 1 << " " << v[0].first << endl;
  }
  return 0;
}
Problem p00099 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define FOR(v, a, b) for (int v = (a); v < (b); ++v)
#define FORE(v, a, b) for (int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define RS resize
#define CLR clear
#define PB push_back
#define ALL(x) (x).begin(), (x).end()
#define INF (~(1 << 31))
#define N_INF (1 << 31)
using namespace std;

void split(string str, char chr, vector<string> *res) {
  stringstream ss(str);
  string itm;
  while (getline(ss, itm, chr)) {
    (*res).PB(itm);
  }
}

class RangeMaxQuery {
private:
  vector<int> value;
  int _size;

public:
  void Init(int size) {
    int bitcount = 0;
    int t = size;

    while (t != 0) {
      t /= 2;
      ++bitcount;
    }
    if (size % (1 << (bitcount - 1)) != 0)
      bitcount++;
    _size = (1 << bitcount) - 1;

    value.resize(_size);

    for (vector<int>::iterator it = value.begin(); it != value.end(); ++it) {
      (*it) = 0;
    }
  }

  void Update(int index, int v) {
    int n = index + (_size >> 1);
    value[n] += v;

    while (n > 0) {
      n = (n - 1) / 2;
      value[n] = max(value[n * 2 + 1], value[n * 2 + 2]);
    }
  }

  void RunQuery(int *max, int *node) {
    *max = value[0];
    *node = 0;

    while (*node < (_size >> 1)) {
      if (value[2 * (*node) + 1] == *max) {
        *node = 2 * (*node) + 1;
      } else {
        *node = 2 * (*node) + 2;
      }
    }

    *node -= (_size >> 1);
  }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, q, a, v, maximum, node;
  RangeMaxQuery rmq;

  cin >> n >> q;
  rmq.Init(n);

  REP(i, q) {
    cin >> a >> v;

    rmq.Update(a - 1, v);
    rmq.RunQuery(&maximum, &node);

    cout << node + 1 << " " << maximum << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int n, q, a, v, max;
  int *plyr;

  cin >> n >> q;

  plyr = new int[n];

  for (int i = n - 1; i >= 0; --i)
    plyr[i] = 0;

  for (int i = q - 1; i >= 0; --i) {

    cin >> a >> v;

    plyr[a - 1] += v;

    max = 0;
    for (int j = 0; j < n; ++j) {
      max = (plyr[j] > plyr[max]) ? j : max;
    }

    cout << max + 1 << " " << plyr[max] << endl;
  }

  delete[] plyr;
}
Problem p00099 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
struct P {
  int a, v;

  bool operator<(const P &t) const {
    if (v == t.v)
      return a > t.a;
    return v < t.v;
  }
};

int n;
P dat[10000000];

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

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

  for (int i = 1;; i *= 2) {
    if (n <= i) {
      n = i;
      break;
    }
  }
  for (int i = 0; i < n; i++) {
    dat[i + n - 1].a = i;
  }

  for (int i = 0; i < q; i++) {
    int a, v;
    scanf("%d %d", &a, &v);
    a--;
    update(a, v);
    printf("%d %d\\n", dat[0].a + 1, dat[0].v);
  }

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
struct P {
  int a, v;

  bool operator<(const P &t) const {
    if (v == t.v)
      return a > t.a;
    return v < t.v;
  }
};

int n;
P dat[2000000];

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

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

  for (int i = 1;; i *= 2) {
    if (n <= i) {
      n = i;
      break;
    }
  }
  for (int i = 0; i < n; i++) {
    dat[i + n - 1].a = i;
  }

  for (int i = 0; i < q; i++) {
    int a, v;
    scanf("%d %d", &a, &v);
    a--;
    update(a, v);
    printf("%d %d\\n", dat[0].a + 1, dat[0].v);
  }

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

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

int main() {
  int n, q, fig, value;
  cin >> n >> q;
  vector<int> memo(n + 1);
  fill(memo.begin(), memo.end(), 0);
  priority_queue<pair<int, int>> que;
  que.push(make_pair(0, -1));
  while (q--) {
    cin >> fig >> value;
    memo[fig] += value;
    que.push(make_pair(memo[fig], -fig));
    for (;;) {
      if (que.top().first == memo[-que.top().second]) {
        cout << -que.top().second << " " << que.top().first << endl;
        break;
      }
      que.pop();
    }
  }
}

Error: MLE

Fixed submission:

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

int main() {
  int n, q, fig, value;
  cin >> n >> q;
  vector<int> memo(n + 1);
  fill(memo.begin(), memo.end(), 0);
  priority_queue<pair<int, int>> que;
  que.push(make_pair(0, -1));
  while (q--) {
    cin >> fig >> value;
    memo[fig] += value;
    for (int i = 1; i <= n; i++)
      que.push(make_pair(memo[i], -i));
    for (;;) {
      if (que.top().first == memo[-que.top().second]) {
        cout << -que.top().second << " " << que.top().first << endl;
        break;
      }
      que.pop();
    }
  }
}