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

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> Pi;
typedef long long int64;

int N;
Pi data[300000];

bool calc(int value) { // 閉じこめられる微生物value

  priority_queue<Pi, vector<Pi>, greater<Pi>>
      que;       // 許容量が小さい順に取り出す(?)
  int64 sum = 0; // 放出量の和

  for (int i = 0; i < value - 1; i++) { // 人数分入れる
    sum += data[i].first;
    que.push(Pi(data[i].second, data[i].first)); // Pi( 許容量, 放出量)
  }

  for (int i = value - 1; i < N; i++) {
    sum += data[i].first;
    que.push(Pi(data[i].second, data[i].first));
    while (!que.empty() && (int64)que.top().first * value < sum) {
      sum -= que.top().second;
      que.pop();
    }
    if (que.size() >= value)
      return true;
  }
  return value == 0;
}

int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d %d", &data[i].first, &data[i].second);
  }
  sort(data, data + N);

  // これわかんないな
  int row = 0, high = N;
  while (high != row) {
    int mid = (row + high + 1) >> 1;
    if (calc(mid))
      row = mid;
    else
      high = mid - 1;
  }
  printf("%d\\n", high);
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> Pi;
typedef long long int64;

int N;
Pi data[300000];

bool calc(int value) { // 閉じこめられる微生物value

  priority_queue<Pi, vector<Pi>, greater<Pi>>
      que;       // 許容量が小さい順に取り出す(?)
  int64 sum = 0; // 放出量の和

  for (int i = 0; i < value - 1; i++) { // 人数分入れる
    sum += data[i].first;
    que.push(Pi(data[i].second, data[i].first)); // Pi( 許容量, 放出量)
  }

  for (int i = value - 1; i < N; i++) {
    sum += data[i].first;
    que.push(Pi(data[i].second, data[i].first));
    while (!que.empty() && que.top().first * value < sum) {
      sum -= que.top().second;
      que.pop();
    }
    if (que.size() >= value)
      return true;
  }
  return value == 0;
}

int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d %d", &data[i].first, &data[i].second);
  }
  sort(data, data + N);

  // これわかんないな
  int row = 0, high = N;
  while (high != row) {
    int mid = (row + high) >> 1;
    if (calc(mid))
      row = mid;
    else
      high = mid - 1;
  }
  printf("%d\\n", high);
}
Problem p00487 (C++) — buggy submission, verdict: Runtime Error

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

int N, n;
pair<int, int> p[300000];
bool ok(int t) {
  priority_queue<int> Q;
  ll sum = 0;
  for (int i = n - 1; i >= n - t + 1; i--) {
    Q.push(p[i].second);
    sum += p[i].second;
  }
  if (p[n - t].first * (ll)t >= (ll)sum + p[n - t].second)
    return 1;
  for (int i = n - t; i > 0; i--) {
    if (!Q.empty() && Q.top() > p[i].second) {
      sum -= Q.top() - p[i].second;
      Q.pop();
      Q.push(p[i].second);
    }
    if (p[i - 1].first * (ll)t >= (ll)sum + p[i - 1].second)
      return 1;
  }
  return 0;
}
int main() {
  scanf("%d", &n);
  rep(i, n) {
    int a, b;
    scanf("%d%d", &a, &b);
    p[i] = {b, a};
  }
  sort(p, p + n);
  int a = 0, b = n;
  while (a != b) {
    int t = (a + b) / 2;
    if (b - a == 1)
      t = b;
    if (ok(t))
      a = t;
    else
      b = t - 1;
  }
  printf("%d\\n", a);
}

Error: 0

Fixed submission:

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

int N, n;
pair<int, int> p[300000];
bool ok(int t) {
  priority_queue<int> Q;
  ll sum = 0;
  for (int i = n - 1; i >= n - t + 1; i--) {
    Q.push(p[i].second);
    sum += p[i].second;
  }
  if (p[n - t].first * (ll)t >= (ll)sum + p[n - t].second)
    return 1;
  for (int i = n - t; i > 0; i--) {
    if (Q.top() > p[i].second) {
      sum -= Q.top() - p[i].second;
      Q.pop();
      Q.push(p[i].second);
    }
    if (p[i - 1].first * (ll)t >= (ll)sum + p[i - 1].second)
      return 1;
  }
  return 0;
}
int main() {
  scanf("%d", &n);
  rep(i, n) {
    int a, b;
    scanf("%d%d", &a, &b);
    p[i] = {b, a};
  }
  sort(p, p + n);
  int a = 0, b = n;
  while (a != b) {
    int t = (a + b) / 2;
    if (b - a == 1)
      t = b;
    if (ok(t))
      a = t;
    else
      b = t - 1;
  }
  printf("%d\\n", a);
}
Problem p00487 (C++) — buggy submission, verdict: Runtime Error

// O(n log^2 n)

#include <algorithm>
#include <cstdio>
#include <set>

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

using namespace std;

typedef long long ll;

int n, hp[300000], emit[300000];

// num 匹の微生物を生かせるかを判定
bool check(int num) {
  multiset<int> S;
  ll emit_sum = 0;
  for (int i = n - 1; i >= 0; i--) { // 生かす微生物の最小 HP を決めうち
    emit_sum += emit[i];
    S.insert(emit[i]);
    if (S.size() < num)
      continue;
    if (S.size() > num) { // S.size()==num+1
      // emit が一番大きい微生物は使わない
      emit_sum -= *S.rbegin();
      S.erase(--S.end());
    }
    if ((ll)num * hp[i] >= emit_sum)
      return true;
  }
  return false;
}

int main() {
  scanf("%d", &n);
  static pair<int, int> tmp[300000];
  rep(i, n) scanf("%d%d", &tmp[i].second, &tmp[i].first);
  sort(tmp, tmp + n);
  rep(i, n) {
    hp[i] = tmp[i].first;
    emit[i] = tmp[i].second;
  }

  int lo = 0, hi = n;
  while (lo < hi) {
    int mi = (lo + hi + 1) / 2;
    if (check(mi))
      lo = mi;
    else
      hi = mi - 1;
  }
  printf("%d\\n", lo);

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <set>

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

using namespace std;

typedef long long ll;

int n, hp[100000], emit[100000];

// num 匹の微生物を生かせるかを判定
bool check(int num) {
  multiset<int> S;
  ll emit_sum = 0;
  for (int i = n - 1; i >= 0; i--) { // 生かす微生物の最小 HP を決めうち
    emit_sum += emit[i];
    S.insert(emit[i]);
    if (S.size() < num)
      continue;
    if (S.size() > num) { // S.size()==num+1
      // emit が一番大きい微生物は使わない
      emit_sum -= *S.rbegin();
      S.erase(--S.end());
    }
    if ((ll)num * hp[i] >= emit_sum)
      return true;
  }
  return false;
}

int main() {
  scanf("%d", &n);
  static pair<int, int> tmp[100000];
  rep(i, n) scanf("%d%d", &tmp[i].second, &tmp[i].first);
  sort(tmp, tmp + n);
  rep(i, n) {
    hp[i] = tmp[i].first;
    emit[i] = tmp[i].second;
  }

  int lo = 0, hi = n;
  while (lo < hi) {
    int mi = (lo + hi + 1) / 2;
    if (check(mi))
      lo = mi;
    else
      hi = mi - 1;
  }
  printf("%d\\n", lo);

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

#include <bits/stdc++.h>
#define filein(t) freopen(t, "r", stdin)
#define fileout(t) freopen(t, "w", stdout)
#define f first
#define s second
#define cs 137
#define ll long long
#define mp make_pair
#define N 300025
#define ln 1e16
#define oo 111539786
#define Pa pair<int, int>
#define Pi pair<int, Pa>

using namespace std;

Pa a[N];
priority_queue<int> que;
int n;

bool Check(int X) {
  while (!que.empty())
    que.pop();
  ll S = 0;
  for (int i = n; i > n - X; i--) {
    que.push(a[i].s);
    S += a[i].s;
  }
  if (S <= (ll)X * a[n - X + 1].f)
    return true;
  for (int i = n - X; i >= 1; i--) {
    int Max = que.top();
    if (Max > a[i].s) {
      S = S - Max + a[i].s;
      que.pop();
      que.push(a[i].s);
    }
    if (S <= (ll)X * a[i].f)
      return true;
  }
  return false;
}

int main() {
  //    filein("MICROORGANISM.inp");    fileout("MICROORGANISM.out");
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i].s >> a[i].f;
  sort(a + 1, a + n + 1);
  int L = 0;
  int R = n + 1;
  while (R - L > 1) {
    int X = (L + R) / 2;
    if (Check(X))
      L = X;
    else
      R = X;
  }
  cout << L << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define filein(t) freopen(t, "r", stdin)
#define fileout(t) freopen(t, "w", stdout)
#define f first
#define s second
#define cs 137
#define ll long long
#define mp make_pair
#define N 100025
#define ln 1e16
#define oo 111539786
#define Pa pair<int, int>
#define Pi pair<int, Pa>

using namespace std;

Pa a[N];
priority_queue<int> que;
int n;

bool Check(int X) {
  while (!que.empty())
    que.pop();
  ll S = 0;
  for (int i = n; i > n - X; i--) {
    que.push(a[i].s);
    S += a[i].s;
  }
  if (S <= (ll)X * a[n - X + 1].f)
    return true;
  for (int i = n - X; i >= 1; i--) {
    int Max = que.top();
    if (Max > a[i].s) {
      S = S - Max + a[i].s;
      que.pop();
      que.push(a[i].s);
    }
    if (S <= (ll)X * a[i].f)
      return true;
  }
  return false;
}

int main() {
  //    filein("MICROORGANISM.inp");    fileout("MICROORGANISM.out");
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i].s >> a[i].f;
  sort(a + 1, a + n + 1);
  int L = 0;
  int R = n + 1;
  while (R - L > 1) {
    int X = (L + R) / 2;
    if (Check(X))
      L = X;
    else
      R = X;
  }
  cout << L << endl;
}
Problem p00488 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
int main() {
  int p[3], j[2];
  int pmin = 2000, jmin = 2000;
  for (int i = 0; i < 3; i++) {
    std::cin >> p[i];
    if (p[i] < pmin) {
      pmin = p[i];
    }
  }
  for (int i = 0; i < 2; i++) {
    std::cin >> j[i];
    if (j[i] < jmin) {
      jmin = j[i];
    }
  }
  std::cout << jmin + pmin - 50 << std::endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
int main() {
  int p[3], j[2];
  int pmin = 2000, jmin = 2000;
  for (int i = 0; 1 < 3; i++) {
    std::cin >> p[i];
    if (p[i] < 2000) {
      pmin = p[i];
    }
  }
  for (int i = 0; 1 < 2; i++) {
    std::cin >> j[i];
    if (j[i] < 2000) {
      jmin = j[i];
    }
  }
  std::cout << jmin + pmin - 50 << std::endl;

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

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

int main() {
  int n, s[101], cop[101], rank[10101];

  cin >> n;
  for (int i = 0; i < n * (n - 1) / 2; i++) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (c == d) {
      s[a - 1]++;
      s[b - 1]++;
    } else {
      (c > d ? s[a - 1] : s[b - 1]) += 3;
    }
  }

  for (int i = 0; i < n; i++)
    cop[i] = s[i];
  sort(cop, cop + n);
  reverse(cop, cop + n);
  for (int i = n - 1; i >= 0; i--) {
    rank[cop[i]] = i + 1;
  }

  for (int i = 0; i < n; i++) {
    cout << rank[s[i]] << endl;
  }
}

Error: -11

Fixed submission:

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

int main() {
  int n, s[100], cop[100], rank[100];

  cin >> n;
  for (int i = 0; i < n * (n - 1) / 2; i++) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (c == d) {
      s[a - 1]++;
      s[b - 1]++;
    } else {
      (c > d ? s[a - 1] : s[b - 1]) += 3;
    }
  }

  for (int i = 0; i < n; i++)
    cop[i] = s[i];
  sort(cop, cop + n);
  reverse(cop, cop + n);
  for (int i = n - 1; i >= 0; i--) {
    rank[cop[i]] = i + 1;
  }

  for (int i = 0; i < n; i++) {
    cout << rank[s[i]] << endl;
  }
}
Problem p00489 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int main(void) {
  int a, s, d, f, g, h[10001], i, j, z[10001];
  scanf("%d", &a);
  for (i = 1; i <= a; i++) {
    z[i] = 1;
    // printf("%d\\n",z[4]);
  }
  //	printf("%d\\n",z[4]);
  for (i = 1; i <= a * (a - 1) / 2; i++) {
    h[i] = 0;
  }
  for (i = 1; i <= a * (a - 1) / 2; i++) {
    scanf("%d %d %d %d", &s, &d, &f, &g);
    if (f < g) {
      h[d] = h[d] + 3;
    } else if (f > g) {
      h[s] = h[s] + 3;
    } else if (f == g) {
      h[d]++;
      h[s]++;
    }
  }
  for (i = 1; i <= a; i++) {
    for (j = 1; j <= a; j++) {
      if (h[i] < h[j]) {
        z[i]++;
        //	printf("z[%d]=%d\\n",i,z[i]);
      }
    }
  }
  for (i = 1; i <= a; i++) {
    printf("%d\\n", z[i]);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>
int main(void) {
  int a, s, d, f, g, h[101], i, j, z[101];
  scanf("%d", &a);
  for (i = 1; i <= a; i++) {
    z[i] = 1;
    // printf("%d\\n",z[4]);
  }
  //	printf("%d\\n",z[4]);
  for (i = 1; i <= a * (a - 1) / 2; i++) {
    h[i] = 0;
  }
  for (i = 1; i <= a * (a - 1) / 2; i++) {
    scanf("%d %d %d %d", &s, &d, &f, &g);
    if (f < g) {
      h[d] = h[d] + 3;
    } else if (f > g) {
      h[s] = h[s] + 3;
    } else if (f == g) {
      h[d]++;
      h[s]++;
    }
  }
  for (i = 1; i <= a; i++) {
    for (j = 1; j <= a; j++) {
      if (h[i] < h[j]) {
        z[i] = z[i] + 1;
        //	printf("z[%d]=%d\\n",i,z[i]);
      }
    }
  }
  for (i = 1; i <= a; i++) {
    printf("%d\\n", z[i]);
  }
  return 0;
}
Problem p00489 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n;
  int score[10000] = {0}, a, b, c, d;

  cin >> n;
  for (int i = 0; i < n * (n - 1) / 2; i++) {
    cin >> a >> b >> c >> d;
    if (c > d) {
      score[a - 1] += 3;
    } else if (c < d) {
      score[b - 1] += 3;
    } else {
      score[a - 1] += 1;
      score[b - 1] += 1;
    }
  }

  int cnt;
  for (int i = 0; i < n; i++) {
    cnt = 0;
    for (int j = 0; j < n * (n - 1) / 2; j++) {
      if (score[j] > score[i])
        cnt++;
    }
    cout << cnt + 1 << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int n;
  int score[100] = {0}, a, b, c, d;

  cin >> n;
  for (int i = 0; i < n * (n - 1) / 2; i++) {
    cin >> a >> b >> c >> d;
    if (c > d) {
      score[a - 1] += 3;
    } else if (c < d) {
      score[b - 1] += 3;
    } else {
      score[a - 1] += 1;
      score[b - 1] += 1;
    }
  }

  int cnt;
  for (int i = 0; i < n; i++) {
    cnt = 0;
    for (int j = 0; j < n * (n - 1) / 2; j++) {
      if (score[j] > score[i])
        cnt++;
    }
    cout << cnt + 1 << endl;
  }

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

#include <bits/stdc++.h>

using namespace std;

int score[100];
int ans[100];
vector<int> rnk[301];

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

  for (int i = 0; i < (n * (n - 1) / 2); ++i) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    a--;
    b--;
    if (c > d) {
      score[a] += 3;
    } else if (d > c) {
      score[b] += 3;
    } else {
      score[a]++;
      score[b]++;
    }
  }

  for (int i = n - 1; i >= 0; --i) {
    rnk[score[i]].push_back(i);
  }

  int r = 1;

  for (int i = 300; i >= 0; --i) {
    int cnt = 0;
    while (rnk[i].size()) {
      ans[rnk[i].back()] = r;
      rnk[i].pop_back();
      cnt++;
    }
    r += cnt;
  }

  for (int i = 0; i < n; ++i)
    printf("%d\\n", ans[i]);
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int score[100];
  int ans[100];
  vector<int> rnk[301];

  int n;
  cin >> n;

  for (int i = 0; i < (n * (n - 1) / 2); ++i) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    a--;
    b--;
    if (c > d) {
      score[a] += 3;
    } else if (d > c) {
      score[b] += 3;
    } else {
      score[a]++;
      score[b]++;
    }
  }

  for (int i = n - 1; i >= 0; --i)
    rnk[score[i]].push_back(i);

  int r = 1;

  for (int i = 300; i >= 0; --i) {
    int cnt = 0;
    while (rnk[i].size()) {
      ans[rnk[i].back()] = r;
      rnk[i].pop_back();
      cnt++;
    }
    r += cnt;
  }

  for (int i = 0; i < n; ++i)
    printf("%d\\n", ans[i]);
}
Problem p00489 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int point[100], team[100], rank[100];
int main() {
  int n, i, j, a, b, c, d, tmp;
  cin >> n;
  for (i = 0; i < 100; i++) {
    team[i] = i + 1;
    point[i] = 0;
  }
  for (i = 0; i < (n * (n - 1) / 2); i++) {
    cin >> a >> b >> c >> d;
    if (c > d) {
      point[a - 1] += 3;
    } else if (c < d) {
      point[b - 1] += 3;
    } else if (c == d) {
      point[a - 1]++;
      point[b - 1]++;
    }
  }
  for (i = 0; i < n - 1; i++) {
    for (j = n - 1; j > i; j--) {
      if (point[i] < point[j]) {
        tmp = point[j];
        point[j] = point[i];
        point[i] = tmp;
        tmp = team[j];
        team[j] = team[i];
        team[i] = tmp;
      }
    }
  }
  for (i = 0; i < n; i++) {
    if (i != 0) {
      if (point[i - 1] == point[i]) {
        rank[team[i] - 1] = rank[team[i - 1] - 1];
      } else {
        rank[team[i] - 1] = i + 1;
      }
    } else
      rank[team[i] - 1] = i + 1;
  }
  for (i = 0; i < n; i++) {
    cout << rank[i] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int n, a, b, pa, pb, point[101], rank[101];
  while (cin >> n, n) {
    for (int i = 0; i < 101; ++i) {
      point[i] = 0;
      rank[i] = 1;
    }
    for (int i = 0; i < ((n * (n - 1)) / 2); ++i) {
      cin >> a >> b >> pa >> pb;
      --a;
      --b;
      if (pa > pb)
        point[a] += 3;
      else if (pa < pb)
        point[b] += 3;
      else {
        ++point[a];
        ++point[b];
      }
    }
    for (int i = 0; i < n; ++i) {
      a = 1;
      pa = point[i];
      for (int j = 0; j < n; ++j) {
        if (pa < point[j])
          ++a;
      }
      rank[i] = a;
    }
    for (int i = 0; i < n; ++i) {
      cout << rank[i] << endl;
    }
  }
  return 0;
}
Problem p00489 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>

using namespace std;

int main(void) {
  int k, n, a[5001], b[5001], c[5001], d[5001], t[5001] = {0};
  int cnt;
  cin >> n;
  k = n * (n - 1) / 2;
  for (int i = 0; i < k; i++)
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  for (int i = 0; i < k; i++) {
    if (c[i] > d[i])
      t[a[i]] += 3;
    else if (c[i] < d[i])
      t[b[i]] += 3;
    else {
      t[a[i]] += 1;
      t[b[i]] += 1;
    }
  }

  for (int i = 1; i <= n; i++) {
    cnt = 1;
    for (int j = 1; j <= n; j++) {
      if (t[i] < t[j])
        cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <cstdio>
#include <iostream>

using namespace std;

int main(void) {
  int k, n, a[101], b[101], c[101], d[101], t[101] = {0};
  int cnt;
  cin >> n;
  k = n * (n - 1) / 2;
  for (int i = 0; i < k; i++)
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  for (int i = 0; i < k; i++) {
    if (c[i] > d[i])
      t[a[i]] += 3;
    else if (c[i] < d[i])
      t[b[i]] += 3;
    else {
      t[a[i]] += 1;
      t[b[i]] += 1;
    }
  }

  for (int i = 1; i <= n; i++) {
    cnt = 1;
    for (int j = 1; j <= n; j++) {
      if (t[i] < t[j])
        cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}
Problem p00489 (C++) — buggy submission, verdict: Runtime Error

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

int n = 0;
int ans[3][120] = {0};

void sortSp(bool flg) {
  vector<pi3> cmp;
  int x = 0;
  int y = 0;
  int z = 2;

  if (flg)
    y = 1;
  else
    x = 1;

  for (int i = 0; i < n; i++) {
    cmp.push_back(pi3(ans[x][i], pii(ans[y][i], ans[z][i])));
  }

  if (flg) {
    sort(cmp.begin(), cmp.end());
  } else {
    sort(cmp.begin(), cmp.end(), greater<pi3>());
  }

  for (int i = 0; i < n; i++) {
    ans[x][i] = cmp[i].first;
    ans[y][i] = cmp[i].second.first;
    ans[z][i] = cmp[i].second.second;
  }
}

void Rank() {
  sortSp(0);

  for (int i = 1; i <= n; i++) {
    int cmp = 0;
    ans[2][i - 1] = i;
    for (int j = i; j < n; j++) {
      if (ans[1][i - 1] == ans[1][j]) {
        ans[2][j] = i;
        cmp++;
      } else
        break;
    }
    i += cmp;
  }

  sortSp(1);
}

void solve(int A, int B, int C) {
  if (!C) {
    ans[1][A - 1] += 1;
    ans[1][B - 1] += 1;
  } else {
    if (C > 0) {
      ans[1][A - 1] += 3;
    } else if (C < 0) {
      ans[1][B - 1] += 3;
    }
  }
}

int main() {
  int A = 0;
  int B = 0;
  int score[2] = {0};
  cin >> n;
  for (int i = 1; i <= n; i++) {
    ans[0][i - 1] = i;
  }
  for (int i = 0; i < n * (n - 1) / 2; i++) {
    cin >> A >> B >> score[0] >> score[1];
    solve(A, B, (score[0] - score[1]));
  }
  Rank();
  for (int i = 0; i < n; i++) {
    printf("%d\\n", ans[2][i]);
  }
  return 0;
}

Error: 0

Fixed submission:

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

int n = 0;
int ans[3][120] = {0};

void sortSp(bool flg) {
  vector<pi3> cmp;
  int x = 0;
  int y = 0;
  int z = 2;

  if (flg)
    y = 1;
  else
    x = 1;

  for (int i = 0; i < n; i++) {
    cmp.push_back(pi3(ans[x][i], pii(ans[y][i], ans[z][i])));
  }

  if (flg) {
    sort(cmp.begin(), cmp.end());
  } else {
    sort(cmp.begin(), cmp.end(), greater<pi3>());
  }

  for (int i = 0; i < n; i++) {
    ans[x][i] = cmp[i].first;
    ans[y][i] = cmp[i].second.first;
    ans[z][i] = cmp[i].second.second;
  }
}

void Rank() {
  sortSp(0);

  for (int i = 1; i <= n; i++) {
    int cmp = 0;
    ans[2][i - 1] = i;
    for (int j = i; j <= n; j++) {
      if (ans[1][i - 1] == ans[1][j]) {
        ans[2][j] = i;
        cmp++;
      } else
        break;
    }
    i += cmp;
  }

  sortSp(1);
}

void solve(int A, int B, int C) {
  if (!C) {
    ans[1][A - 1] += 1;
    ans[1][B - 1] += 1;
  } else {
    if (C > 0) {
      ans[1][A - 1] += 3;
    } else if (C < 0) {
      ans[1][B - 1] += 3;
    }
  }
}

int main() {
  int A = 0;
  int B = 0;
  int score[2] = {0};
  cin >> n;
  for (int i = 0; i < n * (n - 1) / 2; i++) {
    cin >> A >> B >> score[0] >> score[1];
    ans[0][i] = i + 1;
    solve(A, B, (score[0] - score[1]));
  }
  Rank();
  for (int i = 0; i < n; i++) {
    printf("%d\\n", ans[2][i]);
  }
  return 0;
}
Problem p00489 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <stdio.h>
using namespace std;
int main(void) {
  int n, i, j, a[5001], b[5001], c[5001], d[5001], p = 0, team1[5001],
                                                   result[5001], cnt = 0, z = 0;

  cin >> n;

  for (i = 0; i < 5001; i++) {
    a[i] = 0;
    b[i] = 0;
    c[i] = 0;
    d[i] = 0;
    team1[i] = 0;
    result[i] = 1;
  }

  p = n * (n - 1) / 2;

  for (i = 1; i <= p; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];

    if (c[i] > d[i]) {
      team1[a[i]] = team1[a[i]] + 3;
    }

    else if (c[i] < d[i]) {
      team1[b[i]] = team1[b[i]] + 3;
    }

    else {
      team1[a[i]] = team1[a[i]] + 1;
      team1[b[i]] = team1[b[i]] + 1;
    }
  }

  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      if (team1[i] < team1[j]) {
        result[i] = result[i] + 1;
      }
    }
  }
  for (i = 1; i <= n; i++) {
    printf("%d\\n", result[i]);
  }

  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
#include <stdio.h>
using namespace std;
int main(void) {
  int n, i, j, a[1001], b[1001], c[1001], d[1001], p = 0, team1[1001],
                                                   result[1001], cnt = 0, z = 0;

  cin >> n;

  for (i = 0; i <= 1001; i++) {
    a[i] = 0;
    b[i] = 0;
    c[i] = 0;
    d[i] = 0;
    team1[i] = 0;
    result[i] = 1;
  }

  p = n * (n - 1) / 2;

  for (i = 1; i <= p; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];

    if (c[i] > d[i]) {
      team1[a[i]] = team1[a[i]] + 3;
    }

    else if (c[i] < d[i]) {
      team1[b[i]] = team1[b[i]] + 3;
    }

    else {
      team1[a[i]] = team1[a[i]] + 1;
      team1[b[i]] = team1[b[i]] + 1;
    }
  }

  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      if (team1[i] < team1[j]) {
        result[i] = result[i] + 1;
      }
    }
  }
  for (i = 1; i <= n; i++) {
    printf("%d\\n", result[i]);
  }

  return 0;
}