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

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

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int c, a, n;
    cin >> c >> a >> n;
    int count = 0;
    while (1) {
      if (a >= 1 && n >= 1 && c >= 1) {
        a -= 1;
        n -= 1;
        c -= 1;
        count++;
      } else
        break;
    }
    while (1) {
      if (a >= 1 && c >= 2) {
        a -= 1;
        c -= 2;
        count++;
      } else
        break;
    }
    while (1) {
      if (c >= 3) {
        c -= 3;
        count++;
      } else
        break;
    }
    cout << count << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int ans;
void calc(int c, int a, int n, int count) {
  int x = 0;
  if (c >= 3) {
    x++;
    calc(c - 3, a, n, count + 1);
  }
  if (c >= 2 && a >= 1) {
    x++;
    calc(c - 2, a - 1, n, count + 1);
  }
  if (a >= 1 && c >= 1 && n >= 1) {
    x++;
    calc(c - 1, a - 1, n - 1, count + 1);
  }
  if (x == 0) {
    if (count > ans)
      ans = count;
    return;
  }
}

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int c, a, n;
    cin >> c >> a >> n;
    ans = 0;
    calc(c, a, n, 0);
    cout << ans << endl;
  }

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

#include <iostream>
using namespace std;
int main() {
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int c, a, n;
    int can = 0, cca = 0, ccc = 0;
    cin >> c >> a >> n;
    if (1 <= n && 1 <= a && 1 <= c) {
      can = min(min(c, a), n);
      a = a - can;
      c = c - can;
    }
    if (1 <= a && 1 <= c / 2) {
      cca = min(c / 2, a);
      c = c - cca * 2;
    }

    if (1 <= c / 3) {
      ccc = c / 3;
    }

    cout << can + cca + ccc << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int c, a, n, can = 0, cca = 0, ccc = 0;
    cin >> c >> a >> n;
    for (int j = 0; j < n; j++) {
      if (1 <= n && 1 <= a && 1 <= c) {
        can++;
        n--;
        a--;
        c--;
      }
    }
    for (int j = 0; j < a; j++) {
      if (1 <= a && 2 <= c) {
        cca++;
        c = c - 2;
        a--;
      }
    }
    for (int j = 0; j < c; j = j * 3) {
      if (1 <= a && 2 <= c) {
        ccc++;
        c = c - 3;
      }
    }
    cout << can + cca + ccc << endl;
  }
  return 0;
}
Problem p00276 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {

  int Q, c, a, n, counter, counter2;

  cin >> Q;

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

    cin >> c >> a >> n;
    counter = 0;

    while (1) {

      counter2 = 0;

      if (c >= 1 && a >= 1 && n >= 1) {
        counter++;
        counter2++;
        c--;
        a--;
        n--;
      } else if (c >= 2 && a >= 1) {
        counter++;
        counter2++;
        c -= 2;
        a--;
      } else if (c >= 3) {
        counter++;
        counter2++;
        c -= 3;
      }

      if (counter2 == 0)
        break;
    }

    cout << counter << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {

  int Q, c, a, n, counter;

  cin >> Q;

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

    cin >> c >> a >> n;
    counter = 0;

    while (1) {

      if ((c <= 2 && a == 0) || c == 0 || (c <= 1 && a <= 1 && n == 0))
        break;

      if (c >= 1 && a >= 1 && n >= 1) {
        counter++;
        c--;
        a--;
        n--;
      } else if (c >= 2 && a >= 1) {
        counter++;
        c -= 2;
        a--;
      } else if (c >= 3) {
        counter++;
        c -= 3;
      }
    }

    cout << counter << endl;
  }

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

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

int ans;
/*void dfs(int c,int a,int n,int count){
        if(c>=2&&a>=1){
        //	cout<<"CCA"<<endl;
                dfs(c-2,a-1,n,count+1);
        }
        if(c>=3){
                //cout<<"CCC"<<endl;
                dfs(c-3,a,n,count+1);
        }
        if(c>=1&&a>=1&&n>=1){
                //cout<<"CAN"<<endl;
                dfs (c-1,a-1,n-1,count+1);
        }
        ans=max(ans,count);
        //return count;
}*/

int main() {
  int Q;
  int c, a, n;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> c >> a >> n;
    // dfs(c,a,n,0);
    while (c >= 1 && a >= 1 && n >= 1) {
      ans++, c--, a--, n--;
    }
    while (c >= 2 && a >= 1) {
      ans++, c -= 2, a--;
    }
    while (c >= 3) {
      ans++, c -= 3;
    }
    cout << ans << endl;
    ans = 0;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int ans;
void dfs(int c, int a, int n, int count) {
  if (c >= 2 && a >= 1) {
    //	cout<<"CCA"<<endl;
    dfs(c - 2, a - 1, n, count + 1);
  }
  if (c >= 3) {
    // cout<<"CCC"<<endl;
    dfs(c - 3, a, n, count + 1);
  }
  if (c >= 1 && a >= 1 && n >= 1) {
    // cout<<"CAN"<<endl;
    dfs(c - 1, a - 1, n - 1, count + 1);
  }
  ans = max(ans, count);
  // return count;
}

int main() {
  int Q;
  int c, a, n;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> c >> a >> n;
    dfs(c, a, n, 0);
    cout << ans << endl;
    ans = 0;
  }
  return 0;
}
Problem p00276 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

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

using namespace std;

int ans;

void dfs(vector<int> x, int cnt) {
  if (x[0] >= 1 && x[1] >= 1 && x[2] >= 1) {
    x[0]--;
    x[1]--;
    x[2]--;

    dfs(x, cnt + 1);
  } else if (x[0] >= 2 && x[1] >= 1) {
    x[0] -= 2;
    x[1]--;

    dfs(x, cnt + 1);
  } else if (x[0] >= 3) {
    x[0] -= 3;
    dfs(x, cnt + 1);
  }

  ans = max(ans, cnt);
}

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

  rep(i, n) {
    vector<int> v(3);
    rep(i, 3) cin >> v[i];

    ans = 0;
    dfs(v, 0);

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

Error: MLE

Fixed submission:

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

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

using namespace std;

int ans;
map<pair<vector<int>, int>, bool> m;

void dfs(vector<int> x, int cnt) {
  if (m[make_pair(x, cnt)])
    return;

  m[make_pair(x, cnt)] = true;

  if (x[0] >= 3) {
    x[0] -= 3;
    dfs(x, cnt + 1);
    x[0] += 3;
  }
  if (x[0] >= 2 && x[1] >= 1) {
    x[0] -= 2;
    x[1]--;

    dfs(x, cnt + 1);

    x[0] += 2;
    x[1]++;
  }
  if (x[0] >= 1 && x[1] >= 1 && x[2] >= 1) {
    x[0]--;
    x[1]--;
    x[2]--;

    dfs(x, cnt + 1);

    x[0]++;
    x[1]++;
    x[2]++;
  }

  ans = max(ans, cnt);
}

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

  rep(i, n) {
    vector<int> v(3);
    rep(i, 3) cin >> v[i];

    ans = 0;
    m.clear();
    dfs(v, 0);

    cout << ans << endl;
  }
  return 0;
}
Problem p00276 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

/*
 *
 */
int main(int argc, char **argv) {
  int Q, c, a, n;
  cin >> Q;

  for (int i = 0; i < Q; i++) {
    cin >> c >> a >> n;
    int lim = (c + a + n) / 3, res = 0;
    if (lim > c)
      lim = c;
    int j = 0, k = 0, l = 0;
    for (;
         (j + k + l <= lim && j * 3 + k * 2 + l <= c) && (k + l <= a && l <= n);
         j++) {
      for (; (j + k + l <= lim && j * 3 + k * 2 + l <= c) &&
             (k + l <= a && l <= n);
           k++) {
        for (; (j + k + l <= lim && j * 3 + k * 2 + l <= c) &&
               (k + l <= a && l <= n);
             l++) {
          if (j + k + l > res)
            res = j + k + l;
        }
        l = 0;
      }
      k = 0;
    }
    j = 0;
    cout << res << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

/*
 *
 */
int main(int argc, char **argv) {
  int Q, c, a, n;
  cin >> Q;

  for (int i = 0; i < Q; i++) {
    cin >> c >> a >> n;
    int lim = (c + a + n) / 3, res = 0;
    if (lim > c)
      lim = c;
    int j = 0, k = 0, l = 0;
    for (; j + k + l <= lim; j++) {
      for (; j + k + l <= lim && k + l <= a; k++) {
        for (; j + k + l <= lim && l <= n; l++) {
          if (j * 3 + k * 2 + l <= c && k + l <= a) {
            if (j + k + l > res)
              res = j + k + l;
          }
        }
        l = 0;
      }
      k = 0;
    }
    j = 0;
    cout << res << endl;
  }

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

#include <cstring>
#include <iostream>

using namespace std;

int main() {
  int Q;
  cin >> Q;
  while (Q-- > 0) {
    int c, a, n, ans = 0;
    cin >> c >> a >> n;
    // 1 1 1
    for (int i = 0; i <= n; i++) {
      // 2 1 0
      for (int j = 0; j <= (a - i); j++) {
        // 3 0 0
        for (int k = 0; k <= (c - i - 2 * j) / 3; k++) {
          int c_ = i + 2 * j + 3 * k, a_ = i + j, n_ = i;
          if (c_ <= c && a_ <= a && n_ <= n)
            ans = max(ans, i + j + k);
        }
      }
    }

    cout << ans << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cstring>
#include <iostream>

using namespace std;

int main() {
  int Q;
  cin >> Q;
  while (Q-- > 0) {
    int c, a, n, ans = 0;
    cin >> c >> a >> n;
    // 1 1 1
    for (int i = 0; i <= n; i++) {
      // 2 1 0
      for (int j = 0; j <= (a - i); j++) {
        // 3 0 0
        for (int k = 0; k <= (c - i - 2 * j); k++) {
          int c_ = i + 2 * j + 3 * k, a_ = i + j, n_ = i;
          if (c_ <= c && a_ <= a && n_ <= n)
            ans = max(ans, i + j + k);
        }
      }
    }

    cout << ans << endl;
  }

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

#include <iostream>
using namespace std;

int main() {

  int Q = 0;

  cin >> Q;

  for (int i = 0; i < Q; i++) {
    int c, a, n;

    cin >> c >> a >> n;

    if (c == 0 || (c < 2 && a == 0) || (c == 0 && a == 0 && n == 0)) {
      cout << 0 << endl;
      continue;
    }

    int answer = 0;

    while (c > 0 && a > 0 && n > 0) {
      answer++;
      c--;
      a--;
      n--;
    }

    while (c > 1 && a > 0) {
      answer++;
      c -= 2;
      a--;
    }

    if (c > 2) {
      answer += c / 3;
    }
    cout << answer << endl;
  }

  return 0;
}

Error: MLE

Fixed submission:

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

struct Team {
  int c;
  int a;
  int n;
  int TeamNum;
  Team() {
    c = 0;
    a = 0;
    n = 0;
    TeamNum = 0;
  }
};

void Clear(Team &a, Team &b) {
  a.c = b.c;
  a.a = b.a;
  a.n = b.n;
  a.TeamNum = b.TeamNum;
}

int main() {

  int Q = 0;

  cin >> Q;

  for (int i = 0; i < Q; i++) {
    int c, a, n;

    cin >> c >> a >> n;

    if (c == 0 || (c < 2 && a == 0) || (c == 0 && a == 0 && n == 0)) {
      cout << 0 << endl;
      continue;
    }

    int answer = 0;

    queue<Team> que;

    while (!que.empty()) {
      que.pop();
    }

    Team tmp;

    tmp.c = c;
    tmp.a = a;
    tmp.n = n;
    tmp.TeamNum = 0;

    que.push(tmp);

    while (!que.empty()) {
      tmp = que.front();
      que.pop();

      if (tmp.c < 0 || tmp.a < 0 || tmp.n < 0) {
        tmp.TeamNum--;
        if (answer < tmp.TeamNum) {
          answer = tmp.TeamNum;
        }
        continue;
      }

      tmp.TeamNum += 1;

      Team beforetmp;

      Clear(beforetmp, tmp);

      tmp.c -= 3;

      que.push(tmp);

      Clear(tmp, beforetmp);

      tmp.c -= 2;
      tmp.a -= 1;

      que.push(tmp);

      Clear(tmp, beforetmp);

      tmp.c--;
      tmp.a--;
      tmp.n--;

      que.push(tmp);
    }

    cout << answer << endl;
  }

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

#include <iostream>

using namespace std;

void solve() {
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; ++i) {
    int c, a, n;
    cin >> c >> a >> n;
    int team = min(c, min(a, n));
    c -= team;
    a -= team;
    n -= team;
    if (c >= 2 * a) {
      team += a;
      c -= a * 2;
      a = 0;
    } else {
      team += c / 2;
      a -= c / 2;
      c = 0;
    }
    team += c / 3;
    cout << team << endl;
  }
}

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

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;
int max_team = 0;

void DFS(int c, int a, int n, int team) {
  if (max_team < team) {
    max_team = team;
  }
  if ((c < 2 || a == 0) && (c < 3) && (c == 0 || a == 0 || n == 0)) {
    return;
  } else {
    if (c >= 2 && a >= 1) {
      DFS(c - 2, a - 1, n, team + 1);
    }
    if (c >= 3) {
      DFS(c - 3, a, n, team + 1);
    }
    if (c >= 1 && a >= 1 && n >= 1) {
      DFS(c - 1, a - 1, n - 1, team + 1);
    }
  }
}

void solve() {
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; ++i) {
    max_team = 0;
    int c, a, n;
    cin >> c >> a >> n;
    int team = min(c, min(a, n));
    c -= team;
    a -= team;
    n -= team;
    DFS(c, a, n, team);
    cout << max_team << endl;
    ;
  }
}

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

#include <algorithm>
#include <iostream>
#include <map>
#define INF (2 << 28)
using namespace std;

typedef pair<int, int> iiP;

int n;
iiP seg[4 * 2 * 100001 - 1];

void init(int q) {

  n = 1;
  while (n < q)
    n *= 2;

  for (int i = 0; i < n; i++)
    seg[i] = iiP(-INF, -i);
}

void update(int i, iiP a) {

  i += n - 1;
  seg[i] = a;

  while (i > 0) {
    i = (i - 1) / 2;
    seg[i] = max(seg[i * 2 + 1], seg[i * 2 + 2]);
  }
}
int main() {

  int N, R, L, d, t, x, prev;
  int sumt[100001] = {0}, score[100001] = {0};
  cin >> N >> R >> L;

  init(N);
  cin >> d >> t >> x;
  sumt[1] += t, score[d] += x;
  update(d, iiP(score[d], -d));
  prev = t;
  //  cout << ":" << score[d] << " " << d << endl;
  for (int i = 1; i < R; i++) {
    cin >> d >> t >> x;
    iiP p = seg[0];
    score[d] += x, sumt[-p.second] += t - prev;
    prev = t;
    //\\cout << ":" << score[d] << " " << d << endl;
    update(d, iiP(score[d], -d));
  }
  iiP p = seg[0];
  //  cout << p.first << " " << -p.second << endl;
  sumt[-p.second] += L - prev;

  cout << max_element(sumt + 1, sumt + N + 1) - sumt << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#define INF (2 << 28)
using namespace std;

typedef pair<int, int> iiP;

int n;
iiP seg[2 * 100001 - 1];

void init(int q) {

  n = 1;
  while (n < q)
    n *= 2;

  for (int i = 0; i < n; i++)
    seg[i] = iiP(-INF, -i);
}

void update(int i, iiP a) {

  i += n - 1;
  seg[i] = a;

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

int main() {

  int N, R, L, d, t, x, prev;
  int sumt[100001] = {0}, score[100001] = {0};
  cin >> N >> R >> L;

  init(N);
  cin >> d >> t >> x;
  sumt[1] += t, score[d] += x;
  update(d, iiP(score[d], -d));
  prev = t;
  //  cout << ":" << score[d] << " " << d << endl;
  for (int i = 1; i < R; i++) {
    cin >> d >> t >> x;
    iiP p = seg[0];
    score[d] += x, sumt[-p.second] += t - prev;
    prev = t;
    //\\cout << ":" << score[d] << " " << d << endl;
    update(d, iiP(score[d], -d));
  }
  iiP p = seg[0];
  //  cout << p.first << " " << -p.second << endl;
  sumt[-p.second] += L - prev;

  cout << max_element(sumt + 1, sumt + N + 1) - sumt << endl;
}
Problem p00277 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N, R, L;
  cin >> N >> R >> L;
  vector<long long int> data(N + 1, 0);
  vector<int> timet(N + 1, 0);
  int maxteam = 1;
  int maxs = 0;
  int time = 0;
  int d, t, x;
  for (int i = 0; i < R; i++) {
    cin >> d >> t >> x;
    timet[maxteam] += t - time;
    data[d] += x;
    time = t;
    if (d == maxteam && x >= 0) {
      maxs = data[d];
    } else if (d != maxteam && data[d] < maxs) {
    } else if (data[d] == maxs && d < maxteam) {
      maxteam = d;
    } else {
      maxteam = 1;
      maxs = data[1];
      for (int j = 2; j <= N; j++) {
        if (data[j] > maxs) {
          maxs = data[j];
          maxteam = j;
        }
      }
    }
  }
  timet[maxteam] += L - time;
  int k, ktoku;
  k = 1;
  ktoku = timet[1];
  for (int i = 2; i <= N; i++) {
    if (timet[i] > ktoku) {
      ktoku = timet[i];
      k = i;
    }
  }
  cout << k << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N, R, L;
  cin >> N >> R >> L;
  vector<long long int> data(N + 1, 0);
  vector<int> timet(N + 1, 0);
  int maxteam = 1;
  int maxs = 0;
  int time = 0;
  int d, t, x;
  for (int i = 0; i < R; i++) {
    cin >> d >> t >> x;
    timet[maxteam] += t - time;
    data[d] += x;
    time = t;
    maxteam = 1;
    maxs = data[1];
    for (int j = 2; j <= N; j++) {
      if (data[j] > maxs) {
        maxs = data[j];
        maxteam = j;
      }
    }
  }
  timet[maxteam] += L - time;
  int k, ktoku;
  k = 1;
  ktoku = timet[1];
  for (int i = 2; i <= N; i++) {
    if (timet[i] > ktoku) {
      ktoku = timet[i];
      k = i;
    }
  }
  cout << k << endl;
  return 0;
}
Problem p00277 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
const double PI = acos(-1);
const double EPS = 1e-8;
const int inf = 1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
int main() {
  int n, m, l;
  cin >> n >> m >> l;
  vi sum(n);
  vi sc(n);
  int ma = 0, mai = 0;
  int t = 0;
  int a, b, c;
  while (m--) {
    cin >> a >> b >> c;
    sum[mai] += b - t;
    t = b;
    sc[a - 1] += c;
    if (c < 0 && a - 1 == mai) {
      ma = -inf;
      mai = inf;
      rep(i, n) if (ma < sc[i]) {
        if (ma == sc[i])
          mai = min(mai, i);
        else
          mai = i;
        ma = sc[i];
      }
    } else if (c >= 0) {
      if (sc[a - 1] > ma) {
        ma = sc[a - 1];
        mai = a - 1;
      } else if (sc[a - 1] == ma)
        mai = min(mai, a - 1);
    }
  }
  sum[mai] += l - b;
  ma = 0;
  rep(i, n) if (ma < sum[i]) {
    if (ma == sum[i])
      mai = min(mai, i);
    else
      mai = i;
    ma = sum[i];
  }
  cout << mai + 1 << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
const double PI = acos(-1);
const double EPS = 1e-8;
const int inf = 1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
int main() {
  int n, m, l;
  cin >> n >> m >> l;
  vi sum(n);
  vi sc(n);
  int ma = 0, mai = 0;
  int t = 0;
  int a, b, c;
  while (m--) {
    cin >> a >> b >> c;
    sum[mai] += b - t;
    t = b;
    sc[a - 1] += c;
    if (c < 0) {
      ma = -inf;
      mai = inf;
      rep(i, n) if (ma < sc[i]) {
        if (ma == sc[i])
          mai = min(mai, i);
        else
          mai = i;
        ma = sc[i];
      }
    } else {
      if (sc[a - 1] > ma) {
        ma = sc[a - 1];
        mai = a - 1;
      } else if (sc[a - 1] == ma)
        mai = min(mai, a - 1);
    }
  }
  sum[mai] += l - b;
  ma = 0;
  rep(i, n) if (ma < sum[i]) {
    if (ma == sum[i])
      mai = min(mai, i);
    else
      mai = i;
    ma = sum[i];
  }
  cout << mai + 1 << endl;
}
Problem p00277 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cassert>
#include <iostream>
#include <queue>

using namespace std;

struct Point {
  int score, player;

  bool operator<(const Point &p) const {
    if (score != p.score)
      return score < p.score;
    return player > p.player;
  }
};

/*
  ostream& operator << (ostream& os,const Point& p) {
  os << "(" << p.score << "," << p.player <<")";
}
*/
int main() {

  int N, R, L;
  int d, t, x;
  priority_queue<Point> PQ;
  priority_queue<Point> PQ2;
  int score_sum[100001], time_sum[100001];
  int data[3] = {1, 0, 0};

  cin >> N >> R >> L;

  for (int i = 0; i < 100001; i++) {
    score_sum[i] = 0;
    time_sum[i] = 0;
  }

  for (int i = 1; i <= R; i++) {

    cin >> d >> t >> x;

    PQ.push((Point){score_sum[data[0]], data[0]});

    while (1) {
      if (!PQ.empty() && PQ.top().score == score_sum[PQ.top().player]) {
        time_sum[PQ.top().player] += t - data[1];
        break;
      } else {
        assert(PQ.size());
        PQ.pop();
      }
    }
    PQ2.push((Point){time_sum[PQ.top().player], PQ.top().player});

    score_sum[d] += x;
    data[0] = d;
    data[1] = t;
    data[2] = x;
  }

  PQ.push((Point){score_sum[data[0]], data[0]});
  while (1) {
    if (!PQ.empty() && PQ.top().score == score_sum[PQ.top().player]) {
      time_sum[PQ.top().player] += L - data[1];
      break;
    } else {
      assert(!PQ.empty());
      PQ.pop();
    }
  }
  // cout << PQ.size() << " " << PQ.top().player << endl;
  PQ2.push((Point){time_sum[PQ.top().player], PQ.top().player});

  cout << PQ2.top().player << endl;
  // cout <<PQ2.top().score<<endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <cassert>
#include <iostream>
#include <queue>

using namespace std;

struct Point {
  int score, player;

  bool operator<(const Point &p) const {
    if (score != p.score)
      return score < p.score;
    return player > p.player;
  }
};

/*
  ostream& operator << (ostream& os,const Point& p) {
  os << "(" << p.score << "," << p.player <<")";
}
*/
int main() {

  int N, R, L;
  int d, t, x;
  priority_queue<Point> PQ;
  priority_queue<Point> PQ2;
  int score_sum[100001], time_sum[100001];
  int data[3] = {1, 0, 0};

  cin >> N >> R >> L;

  for (int i = 0; i < 100001; i++) {
    score_sum[i] = 0;
    time_sum[i] = 0;
  }

  for (int i = 1; i <= R; i++) {

    cin >> d >> t >> x;

    PQ.push((Point){score_sum[data[0]], data[0]});

    score_sum[d] += x;

    while (1) {
      if (PQ.top().score == score_sum[PQ.top().player]) {
        time_sum[PQ.top().player] += t - data[1];
        break;
      } else {
        PQ.pop();
      }
    }
    PQ2.push((Point){time_sum[PQ.top().player], PQ.top().player});

    data[0] = d;
    data[1] = t;
    data[2] = x;
  }
  PQ.push((Point){score_sum[data[0]], data[0]});
  while (1) {
    if (PQ.top().score == score_sum[PQ.top().player]) {
      time_sum[PQ.top().player] += L - data[1];
      break;
    } else {
      PQ.pop();
    }
  }
  while (PQ.empty())
    ;
  PQ2.push((Point){time_sum[PQ.top().player], PQ.top().player});

  cout << PQ2.top().player << endl;

  // cout <<PQ2.top().score<<endl;

  return 0;
}