alexjercan/bugnet huggingface dataset:
Problem p00489 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, team1, team2, score1, score2, point[101] = {0};
  vector<int> rank;
  cin >> n;
  for (int i = 0; i < n * (n - 1) / 2; i++) {
    cin >> team1 >> team2 >> score1 >> score2;
    if (score1 > score2)
      point[team1] += 3;
    else if (score1 < score2)
      point[team2] += 3;
    else {
      point[team1]++;
      point[team2]++;
    }
  }

  for (int i = 0; i < n; i++)
    rank.push_back(point[i + 1]);

  stable_sort(rank.begin(), rank.end(), greater<int>());

  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < n; j++) {
      if (point[i] == rank[j]) {
        cout << j + 1 << endl;
        break;
      }
    }
  }

  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int n, team1[100], team2[100], score1[100], score2[100], point[101] = {0};
  vector<int> rank;
  cin >> n;
  for (int i = 0; i < n * (n - 1) / 2; i++) {
    cin >> team1[i] >> team2[i] >> score1[i] >> score2[i];
    if (score1[i] > score2[i])
      point[team1[i]] += 3;
    else if (score1[i] < score2[i])
      point[team2[i]] += 3;
    else {
      point[team1[i]]++;
      point[team2[i]]++;
    }
  }

  for (int i = 0; i < n; i++)
    rank.push_back(point[i + 1]);

  stable_sort(rank.begin(), rank.end(), greater<int>());

  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < n; j++) {
      if (point[i] == rank[j]) {
        cout << j + 1 << endl;
        break;
      }
    }
  }

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

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


Error: WA

Fixed submission:

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

#include <algorithm>
#include <cstdio>
#include <functional>
using namespace std;
int main(void) {
  int n, i, j, gou;
  int a[10001], b[10001], c[10001], d[10001], t[10001], jun[10001];
  scanf("%d", &n);
  gou = n * (n - 1) / 2;
  for (i = 0; i < 10001; i++) {
    t[i] = 0;
    jun[i] = 1;
  }
  for (i = 1; i <= gou; i++) {
    scanf("%d %d %d %d", &a[i], &b[i], &c[i], &d[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 (i = 1; i < n; i++) {
    for (j = 1 + i; j <= n; j++) {
      if (t[i] == t[j]) {
      } else if (t[i] > t[j]) {
        jun[j] += 1;
      } else if (t[i] < t[j]) {
        jun[i] += 1;
      }
    }
  }
  for (i = 1; i <= n; i++) {
    printf("%d\\n", jun[i]);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <functional>
using namespace std;
int main(void) {
  int n, i, j, gou;
  int a[101], b[101], c[101], d[101], t[101], jun[101];
  scanf("%d", &n);
  gou = n * (n - 1) / 2;
  for (i = 0; i < 101; i++) {
    t[i] = 0;
    jun[i] = 1;
  }
  for (i = 1; i <= gou; i++) {
    scanf("%d %d %d %d", &a[i], &b[i], &c[i], &d[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 (i = 1; i < n; i++) {
    for (j = 1 + i; j <= n; j++) {
      if (t[i] == t[j]) {
      } else if (t[i] > t[j]) {
        jun[j] += 1;
      } else if (t[i] < t[j]) {
        jun[i] += 1;
      }
    }
  }
  for (i = 1; i <= n; i++) {
    printf("%d\\n", jun[i]);
  }
  return 0;
}
Problem p00489 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int main(void) {
  int n, i, a, s, d, f, x[101], w[101], q[101], j, o;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    x[i] = 0;
    w[i] = 0;
    q[i] = 0;
  }
  for (i = 1; i <= n * (n - 1) / 2; i++) {
    scanf("%d %d %d %d", &a, &s, &d, &f);
    if (d < f) {
      x[s] += 3;
    }
    if (f < d) {
      x[a] += 3;
    }
    if (d == f) {
      x[a]++;
      x[s]++;
    }
  }
  for (i = 1; i <= n; i++) {
    w[i] = x[i];
  }
  o = 0;
  for (i = 1; i <= n - 1; i++) {
    for (j = i + 1; j <= n; j++) {
      if (x[i] < x[j]) {
        o = x[j];
        x[j] = x[i];
        x[i] = o;
      }
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      if (w[i] == x[j]) {
        w[i] = j;
        break;
      }
    }
  }
  for (i = 1; i <= n; i++) {
    printf("%d\\n", w[i]);
  }
  return 0;
}

Error: 0

Fixed submission:

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

#include <iostream>
#include <string>

using namespace std;

int main() {
  int n;
  int a[11000], b[11000], c[11000], d[11000];
  int t[11000], k[11000];
  cin >> n;
  for (int i = 0; i < (n * (n - 1)) / 2; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    t[i] = 0;
  }
  for (int i = 0; i < (n * (n - 1)) / 2; i++) {
    if (c[i] > d[i])
      t[a[i]] += 3;
    if (c[i] < d[i])
      t[b[i]] += 3;
    if (c[i] == d[i]) {
      t[a[i]]++;
      t[b[i]]++;
    }
  }
  int j = 1;
  int h = 0;
  for (int g = n * 3; g >= 0; g--) {
    for (int i = 1; i < n + 1; i++) {
      if (g == t[i]) {
        k[i] = j;
        h++;
      }
    }
    j += h;
    h = 0;
  }
  for (int i = 1; i < n + 1; i++) {
    cout << k[i] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

int main() {
  int n;
  int a[105], b[105], c[105], d[105];
  int t[11000], k[105];
  cin >> n;
  for (int i = 0; i < (n * (n - 1)) / 2; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    t[i] = 0;
  }
  for (int i = 0; i < (n * (n - 1)) / 2; i++) {
    if (c[i] > d[i])
      t[a[i]] += 3;
    if (c[i] < d[i])
      t[b[i]] += 3;
    if (c[i] == d[i]) {
      t[a[i]]++;
      t[b[i]]++;
    }
  }
  int j = 1;
  int h = 0;
  for (int g = n * 3; g >= 0; g--) {
    for (int i = 1; i < n + 1; i++) {
      if (g == t[i]) {
        k[i] = j;
        h++;
      }
    }
    j += h;
    h = 0;
  }
  for (int i = 1; i < n + 1; i++) {
    cout << k[i] << endl;
  }
  return 0;
}
Problem p00489 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  int score[200], val, ctn[200];
  memset(score, 0, sizeof(score));
  fill(ctn, ctn + 200, 1);

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  int score[200], val, ctn[200];
  memset(score, 0, sizeof(score));
  memset(ctn, 0, sizeof(ctn));
  cin >> val;
  int a, b, c, d;
  for (int i = 0; i < val * (val - 1) / 2; i++) {
    cin >> a >> b >> c >> d;
    if (c < d)
      score[b - 1] += 3;
    else if (c > d)
      score[a - 1] += 3;
    else if (c == d) {
      score[a - 1]++;
      score[b - 1]++;
    }
  }
  for (int a = 0; a < val; b++) {
    for (int b = 0; b < val; b++) {
      if (score[a] < score[b])
        ctn[a]++;
    }
    cout << ctn[a] << endl;
  }
}
Problem p00489 (C++) — buggy submission, verdict: Runtime Error

//
//  main.cpp

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

int main() {
  int n;
  int team[3][10001];
  int point[3][10001];
  int gets[10001];
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 10001; j++)
      gets[j] = team[i][j] = point[i][j] = 0;

  cin >> n;
  for (int i = 0; i < n * (n - 1) / 2; i++) {
    cin >> team[0][i] >> team[1][i] >> point[0][i] >> point[1][i];
  }

  for (int i = 0; i < n * (n - 1) / 2; i++) {
    if (point[0][i] > point[1][i]) {
      gets[team[0][i]] += 3;
    } else if (point[0][i] < point[1][i]) {
      gets[team[1][i]] += 3;
    } else {
      gets[team[0][i]] += 1;
      gets[team[1][i]] += 1;
    }
  }

  vector<pair<int, int>> vec;
  for (int i = 1; i <= n; i++) {
    vec.push_back(make_pair(gets[i], i)); //?????°?????????
  }
  sort(vec.begin(), vec.end());
  int answer[101] = {};
  int memo = -1;
  int count = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (memo == vec[i].first) {
      count++;
    } else {
      memo = vec[i].first;
      count = 0;
    }
    answer[vec[i].second] = n - i - count;
  }
  for (int i = 1; i <= n; i++) {
    cout << answer[i] << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

//
//  main.cpp

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

int main() {
  int n;
  int team[3][101];
  int point[3][101];
  int gets[101];
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 101; j++)
      gets[j] = team[i][j] = point[i][j] = 0;

  cin >> n;
  for (int i = 0; i < n * (n - 1) / 2; i++) {
    cin >> team[0][i] >> team[1][i] >> point[0][i] >> point[1][i];
  }

  for (int i = 0; i < n * (n - 1) / 2; i++) {
    if (point[0][i] > point[1][i]) {
      gets[team[0][i]] += 3;
    } else if (point[0][i] < point[1][i]) {
      gets[team[1][i]] += 3;
    } else {
      gets[team[0][i]] += 1;
      gets[team[1][i]] += 1;
    }
  }

  vector<pair<int, int>> vec;
  for (int i = 1; i <= n; i++) {
    vec.push_back(make_pair(gets[i], i)); //?????°?????????
  }
  sort(vec.begin(), vec.end());
  int answer[101] = {};
  int memo = -1;
  int count = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (memo == vec[i].first) {
      count++;
    } else {
      memo = vec[i].first;
      count = 0;
    }
    answer[vec[i].second] = n - i - count;
  }
  for (int i = 1; i <= n; i++) {
    cout << answer[i] << endl;
  }

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

//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;
int A[5001], B[5001], C[5001], D[5001];
int N, M;
int S[101] = {};
int main() {
  cin >> N;
  for (int i = 0; i < (N * (N - 1) / 2); i++) {
    cin >> A[i] >> B[i] >> C[i] >> D[i];
    if (C[i] > D[i])
      S[A[i]] += 3;
    if (C[i] < D[i])
      S[B[i]] += 3;
    if (C[i] == D[i])
      S[A[i]] += 1, S[B[i]] += 1;
  }

  int T = 0;
  for (int i = 1; i < N + 1; i++) {
    T = 1;
    for (int j = 1; j < N + 1; j++) {
      if (S[i] < S[j])
        T += 1;
    }
    cout << T << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;
int A[101], B[101], C[101], D[101];
int N, M;
int S[101] = {};
int main() {
  cin >> N;
  for (int i = 0; i < (N * (N - 1) / 2); i++) {
    cin >> A[i] >> B[i] >> C[i] >> D[i];
    if (C[i] > D[i])
      S[A[i]] += 3;
    if (C[i] < D[i])
      S[B[i]] += 3;
    if (C[i] == D[i])
      S[A[i]] += 1, S[B[i]] += 1;
  }

  int T = 0;
  for (int i = 1; i < N + 1; i++) {
    T = 1;
    for (int j = 1; j < N + 1; j++) {
      if (S[i] < S[j])
        T += 1;
    }
    cout << T << endl;
  }
  return 0;
}
Problem p00490 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

struct Node {
  int no_;
  int calorie_;
  int price_;

  Node(int n, int c, int p) : no_(n), calorie_(c), price_(p) {}
};

int N, A, B, C;
vector<int> calorie;

int calcBestPizza() {
  int ans = 0;

  stack<Node> st;
  st.push(Node(0, C, A));
  st.push(Node(0, calorie[0] + C, A + B));

  while (!st.empty()) {
    auto node = st.top();
    st.pop();

    int n = node.no_;
    int total_calorie = node.calorie_;
    int total_price = node.price_;
    int tmp = total_calorie / total_price;

    if (tmp > ans) {
      ans = tmp;
    }

    if (n < N - 1) {
      st.push(Node(n + 1, total_calorie, total_price));
      st.push(Node(n + 1, total_calorie + calorie[n + 1], total_price + B));
    }
  }

  return ans;
}

int main(int argc, char const *argv[]) {
  cin >> N;
  cin >> A >> B;
  cin >> C;

  for (int i = 0; i < N; ++i) {
    int c;
    cin >> c;
    calorie.push_back(c);
  }

  sort(calorie.begin(), calorie.end(), greater<int>());
  int total_calorie = C;
  int total_price = A;
  int ans = C / A;
  for (int i = 0; i < N; ++i) {
    total_calorie += calorie[i];
    total_price += B;
    ans = max(ans, total_calorie / total_price);
  }

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <stack>
#include <vector>

using namespace std;

struct Node {
  int no_;
  int calorie_;
  int price_;

  Node(int n, int c, int p) : no_(n), calorie_(c), price_(p) {}
};

int N, A, B, C;
vector<int> calorie;

int calcBestPizza() {
  int ans = 0;

  stack<Node> st;
  st.push(Node(0, C, A));
  st.push(Node(0, calorie[0] + C, A + B));

  while (!st.empty()) {
    auto node = st.top();
    st.pop();

    int n = node.no_;
    int total_calorie = node.calorie_;
    int total_price = node.price_;
    int tmp = total_calorie / total_price;

    if (tmp > ans) {
      ans = tmp;
    }

    if (n < N - 1) {
      st.push(Node(n + 1, total_calorie, total_price));
      st.push(Node(n + 1, total_calorie + calorie[n + 1], total_price + B));
    }
  }

  return ans;
}

int main(int argc, char const *argv[]) {
  cin >> N;
  cin >> A >> B;
  cin >> C;

  for (int i = 0; i < N; ++i) {
    int c;
    cin >> c;
    calorie.push_back(c);
  }

  cout << calcBestPizza() << endl;

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

#include <iostream>
using namespace std;

int main() {
  int n, a, b, c, d[105];
  cin >> n;
  cin >> a >> b;
  cin >> c;
  for (int i = 0; i < n; i++) {
    cin >> d[i];
  }
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      if (d[i] < d[j]) {
        swap(d[i], d[j]);
      }
    }
  }
  int sum = 0;
  int ans = 0;
  int w;
  for (int i = 0; i < n; i++) {
    sum += d[i];
    w = (c + sum) / (b * (i + 1) + a);
    if (w >= ans) {
      ans = (c + sum) / (b * (i + 1) + a);
    } else {
      break;
    }
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int n, a, b, c;
int d[105];
int sum;
int saishou = 0;

void findmin(int i, int r, int m) {
  int e = 0;
  if (r * m)
    e = (m + c) / (a + b * r);
  if (e > saishou && r * m > 0) {
    saishou = e;
  }
  if (i >= n)
    return;
  findmin(i + 1, r, m);
  findmin(i + 1, r + 1, m + d[i]);
}

int main() {
  cin >> n;
  cin >> a >> b;
  cin >> c;
  for (int i = 0; i < n; i++) {
    cin >> d[i];
  }

  findmin(0, 0, 0);

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

#include <algorithm>
#include <functional>
#include <iostream>
using namespace std;
int main() {
  int n, a, b, c, d[100], i;
  double sm, sv, t, u;
  cin >> n >> a >> b >> c;
  for (i = 0; i < n; i++)
    cin >> d[i];
  sort(d, d + n, greater<int>());
  sm = (double)a, sv = (double)c;
  for (i = 0; i < n; i++) {
    t = (sv + d[i]) / (sm + b);
    u = sv / sm;
    if (t > u)
      sv += d[i], sm += b;
  }
  cout << (int)(sv / sm) << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int a, b, c, d[100], n;
double dfs(int i, int m, int k, bool f) {
  if (i == n - 1) {
    if (f)
      return ((double)k + (double)d[i]) / ((double)m + (double)b);
    else
      return (double)k / (double)m;
  }
  if (f)
    return (double)max(dfs(i + 1, m + b, k + d[i], true),
                       dfs(i + 1, m + b, k + d[i], false));
  else
    return (double)max(dfs(i + 1, m, k, true), dfs(i + 1, m, k, false));
}
int main() {
  int i;
  cin >> n >> a >> b >> c;
  for (i = 0; i < n; i++)
    cin >> d[i];
  cout << (int)max(dfs(0, a, c, true), dfs(0, a, c, false)) << endl;
}
Problem p00490 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <queue>

using namespace std;

typedef pair<double, int> P;

int main() {
  int n;
  cin >> n;
  int a, b, c;
  cin >> a >> b;
  cin >> c;
  double base = (double)c / (double)a;
  int nedan = a;
  long long int caro = c;
  int d;
  priority_queue<P> pq;
  for (int i = 0; i < n; i++) {
    cin >> d;
    double k = (double)d / (double)b;
    pq.push(P(k, d));
  }
  while (!pq.empty()) {
    P pp = pq.top();
    pq.pop();
    if (pp.first >= base) {
      nedan += b;
      caro += pp.second;
      base = caro / nedan;
    } else {
      break;
    }
  }
  cout << caro / nedan << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>

using namespace std;

int top[100];

int keisan(int b, long long int karo, int nedan, int limit, int n) {
  if (n == limit) {
    return karo / nedan;
  } else {
    return max(keisan(b, karo + top[n], nedan + b, limit, n + 1),
               keisan(b, karo, nedan, limit, n + 1));
  }
}

int main() {
  int n;
  cin >> n;
  int a, b, c;
  cin >> a >> b;
  cin >> c;
  for (int i = 0; i < n; i++) {
    cin >> top[i];
  }
  cout << keisan(b, c, a, n, 0) << endl;
  return 0;
}
Problem p00490 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

int main() {
  int a, b, n, c;
  int d[10000];
  int sorts;
  int best, bests;
  cin >> n;
  cin >> a >> b;
  cin >> c;
  for (int i = 0; i < n; i++) {
    cin >> d[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; ++j) {
      if (d[j] > d[i]) {
        sorts = d[j];
        d[j] = d[i];
        d[i] = sorts;
      }
    }
  }
  best = a / c;
  for (int i = 0; i < n; i++) {
    bests = (c + d[i]) / (a + b + (b * i));
    c += d[i];
    if (bests > best)
      best = bests;
    if (bests <= best)
      bests = best;
  }
  cout << best << endl;
  return 0;
}

Error: -8

Fixed submission:

#include <algorithm>
#include <functional>
#include <iostream>
#include <string>

using namespace std;

int main() {
  int aa[10000];
  int bb[10000];
  int cc[10000];
  int u = 0;
  int i = 1;

  int a = 0;
  int c = 0;
  int n = 0;
  int t = 0;
  t = c / a;
  cin >> a >> c >> n;
  int b[10000];
  int d[10000];
  double e[10000];
  e[0] = 1;
  while (true) {
    cin >> b[i] >> d[i];
    e[i] = d[i] / b[i];
    if (i > n + 1)
      break;
    else
      i++;
  }
  sort(e, e + n, greater<int>());
  while (true) {
    if (cc[u] < e[i - u] || a / c < e[u]) {
      bb[u] = (c / a) + (e[u] * a);
      cc[u] = bb[u] / 2;
      u++;
    } else
      break;
  }
  cout << cc[u] << endl;
  return 0;
}
Problem p00490 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i, j) for (int i = 0; i < j; i++)
#define FOR(i, j, k) for (int i = j; i < k; i++)
#define P pair<int, int>
const int INF = INT_MAX / 2;

int main() {
  int tn, km, tm, kc, ans = 0;
  vector<int> tc;
  cin >> tn >> km >> tm >> kc;
  tc = vector<int>(tn);
  REP(i, tn) cin >> tc[i];
  sort(tc.begin(), tc.end());
  reverse(tc.begin(), tc.end());
  int sum = 0;
  REP(i, tn) {
    sum += tc[i];
    ans = max(ans, (int)((kc + sum) / (km + (i + 1) * tm)));
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i, j) for (int i = 0; i < j; i++)
#define FOR(i, j, k) for (int i = j; i < k; i++)
#define P pair<int, int>
const int MAX_TN = 101;
const int INF = INT_MAX / 2;
int tn, km, tm, kc, ans = -1;
vector<int> tc;

void loop(int n, int cnt, int c) {
  if (n >= tn)
    ans = max(ans, (int)((kc + c) / (km + (cnt * tm))));
  else {
    loop(n + 1, cnt, c);
    loop(n + 1, cnt + 1, c + tc[n]);
  }
}

int main() {
  cin >> tn >> km >> tm >> kc;
  tc = vector<int>(tn);
  REP(i, tn) cin >> tc[i];
  loop(0, 0, 0);
  cout << ans << endl;
  return 0;
}