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

#include <cstdlib>
#include <iostream>
#include <map>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
  int w, h;
  while (cin >> w >> h, w) {
    int sy, sx, gy, gx, py[5][1000] = {0}, px[5][1000] = {0}, np[5] = {0};
    rep(i, h) {
      char buf[1001];
      cin >> buf;
      rep(j, w) {
        if (buf[j] == 'S')
          sy = i, sx = j;
        if (buf[j] == 'G')
          gy = i, gx = j;
        if ('0' < buf[j] && buf[j] < '6') {
          int e = buf[j] - '1';
          py[e][np[e]] = i, px[e][np[e]] = j;
          np[e]++;
        }
      }
    }
    int cost[5][5][1000], ans = 1 << 20, ae;
    rep(i, 5) rep(j, 5) rep(k, 1000) cost[i][j][k] = 1 << 20;
    for (int s_ = 1; s_ < 6; s_++) {
      int s = s_ % 5;
      rep(i, np[s]) cost[s][s][i] = abs(py[s][i] - sy) + abs(px[s][i] - sx);
      rep(i_, 3) {
        int i = (s + i_) % 5, ni = (i + 1) % 5;
        rep(j, np[ni]) rep(k, np[i]) cost[s][ni][j] =
            min(cost[s][ni][j], cost[s][i][k] + abs(py[ni][j] - py[i][k]) +
                                    abs(px[ni][j] - px[i][k]));
      }
      int l = (s + 3) % 5;
      rep(i, np[l]) {
        int c = cost[s][l][i] + abs(gy - py[l][i]) + abs(gx - px[l][i]);
        if (ans > c)
          ae = s, ans = c;
      }
    }
    if (ans == 1 << 20)
      cout << "NA" << endl;
    else
      cout << (ae + 4) % 5 + 1 << " " << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdlib>
#include <iostream>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ck(a, b) (0 <= a && a < b)
using namespace std;
int dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};
int w, h, m[1000][1000], sx, sy, gx, gy, cost[32][1000][1000], ans, e;
void dfs(int y, int x, int s) {
  if (cost[s][y][x] + abs(gy - y) + abs(gx - x) > cost[31][gy][gx])
    return;
  rep(d, 4) {
    int ny = y + dy[d], nx = x + dx[d], ns;
    if (!ck(ny, h) || !ck(nx, w))
      continue;
    ns = m[ny][nx] != 0 && (s & 1 << (m[ny][nx] + 3) % 5)
             ? s | 1 << (m[ny][nx] - 1)
             : s;
    if (cost[ns][ny][nx] > cost[s][y][x] + 1) {
      if (ny == gy && nx == gx && ns == 31)
        ans = e;
      cost[ns][ny][nx] = cost[s][y][x] + 1, dfs(ny, nx, ns);
    }
  }
}
int main() {
  while (cin >> w >> h, w) {
    int f[5] = {0}, count = 0;
    rep(i, h) rep(j, w) {
      char c;
      cin >> c;
      if (c == 'S')
        sy = i, sx = j;
      if (c == 'G')
        gy = i, gx = j;
      if ('0' < c && c < '6')
        f[c - '1'] = 1, m[i][j] = c - '0';
      else
        m[i][j] = 0;
      rep(k, 32) cost[k][i][j] = 1 << 20;
    }
    rep(i, 5) count += f[i], cost[1 << i][sy][sx] = 0;
    if (count < 4) {
      cout << "NA" << endl;
      continue;
    }
    rep(i, 5) e = i, dfs(sy, sx, 1 << i);
    cout << ans + 1 << " " << cost[31][gy][gx] << endl;
  }
  return 0;
}
Problem p00215 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <vector>
#define INF 1 << 28
#define F first
#define S second
using namespace std;

int sx, sy, gx, gy;
typedef pair<int, int> P;
vector<P> p[5];
int memo[5][5][1111];
int a, b;

int solve(int k, int t, int q) {

  if (k == 4)
    return abs(p[t][q].F - gx) + abs(p[t][q].S - gy);
  if (memo[k][t][q])
    return memo[k][t][q];

  int ans = INF, d = (t + 1) % 5, s;
  for (int i = 0; i < p[d].size(); i++) {
    if (!k)
      s = abs(sx - p[d][i].F) + abs(sy - p[d][i].S);
    else
      s = abs(p[t][q].F - p[d][i].F) + abs(p[t][q].S - p[d][i].S);
    ans = min(ans, solve(k + 1, d, i) + s);
  }

  return memo[k][t][q] = ans;
}

int main() {

  int w, h;
  char c;

  while (true) {
    cin >> w >> h;
    if (!w && !h)
      break;

    for (int i = 0; i < 5; i++)
      p[i].clear();

    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cin >> c;
        if (c == 'S')
          sx = j, sy = i;
        if (c == 'G')
          gx = j, gy = i;
        else if (c != '.')
          p[c - '1'].push_back(P(j, i));
      }
    }

    b = INF;
    for (int i = 0; i < 5; i++) {
      memset(memo, 0, sizeof(memo));
      if (b > solve(0, i, 0))
        a = i, b = solve(0, i, 0);
    }

    if (b == INF)
      cout << "NA\\n";
    else
      cout << a + 1 << " " << b << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <vector>
#define INF 1 << 28
#define F first
#define S second
using namespace std;

int sx, sy, gx, gy;
typedef pair<int, int> P;
vector<P> p[5];
int memo[5][5][1111];
int s, d;

int solve(int k, int t, int q) {

  if (k == 4)
    return abs(p[t][q].F - gx) + abs(p[t][q].S - gy);
  if (memo[k][t][q])
    return memo[k][t][q];

  int ans = INF;
  d = (t + 1) % 5;
  for (int i = 0; i < p[d].size(); i++) {
    if (!k)
      s = abs(sx - p[d][i].F) + abs(sy - p[d][i].S);
    else
      s = abs(p[t][q].F - p[d][i].F) + abs(p[t][q].S - p[d][i].S);
    ans = min(ans, solve(k + 1, d, i) + s);
  }

  return memo[k][t][q] = ans;
}

int main() {

  int w, h;
  char c;

  while (true) {
    cin >> w >> h;
    if (!w && !h)
      break;

    for (int i = 0; i < 5; i++)
      p[i].clear();

    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cin >> c;
        if (c == 'S')
          sx = j, sy = i;
        if (c == 'G')
          gx = j, gy = i;
        else if (c != '.')
          p[c - '1'].push_back(P(j, i));
      }
    }

    P q = P(0, INF);
    for (int i = 0; i < 5; i++) {
      memset(memo, 0, sizeof(memo));
      if (q.S > solve(0, i, 0))
        q.F = i + 1, q.S = solve(0, i, 0);
    }

    if (q.S == INF)
      cout << "NA\\n";
    else
      cout << q.F << " " << q.S << endl;
  }
}
Problem p00216 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
int main(void) {
  int n, w, a;
  while (1) {
    scanf("%d", &n);
    if (n == -1)
      break;
    w = 1150;
    if (n > 30) {
      w = w + (n - 30) * 160;
      if (n >= 40)
        n = 30;
      else
        n = (n / 10) * 10;
    }
    if (n > 20) {
      w = w + (n - 20) * 140;
      if (n == 30)
        n = 20;
      else
        n = (n / 10) * 10;
    }
    if (n > 10) {
      w = w + (n - 10) * 125;
    }
    a = 4280 - w;
    printf("%d\\n", a);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
int main(void) {
  int a, x, y, v, k;
  scanf("%d", &a);
  while (1) {
    if (a <= 0)
      break;
    k = 3130;
    x = 4280 - (a - 10) * 125 - 1150;
    y = 4280 - (a - 20) * 140 - 2400;
    v = 4280 - (a - 30) * 160 - 3800;
    if (a <= 10) {
      printf("%d\\n", k);
    } else if (a <= 20) {
      printf("%d\\n", x);
    } else if (a <= 30) {
      printf("%d\\n", y);
    } else if (30 <= a) {
      printf("%d\\n", v);
    }
  }
  return 0;
}
Problem p00216 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int w, last = 4280;

  while (cin >> w, w != -1) {
    int ans = 1150;
    while (w != 0) {
      if (w > 30) {
        ans += 160 * (w - 30);
        w = 30;
      } else if (w > 20) {
        ans += 140 * (w - 20);
        w = 20;
      } else if (w > 10) {
        ans += 125 * (w - 10);
        w = 10;
      } else
        w = 0;
    }
    cout << last - ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int w, last = 4280;

  while (cin >> w, w != -1) {
    int ans = 1150;
    while (w != 0) {
      if (w > 30) {
        ans += 160 * (w - 30);
        w = 30;
      } else if (w > 20) {
        ans += 140 * (w - 20);
        w = 20;
      } else if (w > 10) {
        ans += 125 * (w - 10);
        w = 0;
      }
    }
    cout << last - ans << endl;
  }
}
Problem p00216 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main(void) {
  int w = 0;
  while (1) {
    cin >> w;
    if (w <= -1)
      break;
    else {
      if (w >= 0 && w < 10) {
        w = 0;
      } else if (w >= 10 && w < 20) {
        w -= 10;
        w *= 125;
      } else if (w >= 20 && w < 30) {
        w -= 20;
        w *= 140;
        w += 1250;
      } else if (w >= 30 && w < 40) {
        w -= 30;
        w *= 160;
        w += 2650;
      } else if (w >= 40 && w <= 100) {
        w -= 40;
        w *= 160;
        w += 4250;
      }
      w += 1150;
      cout << 4280 - w << endl;
    }
  }
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main(void) {
  while (1) {
    int rate;
    cin >> rate;
    if (rate == -1)
      break;
    else {
      if (rate == 0) {
        rate == 0;
      } else {
        rate -= 10;
      }
      while (1) {
        if (rate >= 0 && rate < 10) {
          rate *= 125;
          break;
        } else if (rate >= 10 && rate < 20) {
          rate -= 10;
          rate *= 140;
          rate += 1250;
          break;
        } else if (rate >= 20 && rate <= 30) {
          rate -= 20;
          rate *= 160;
          rate += 2650;
          break;
        }
      }
      rate += 1150;
      cout << 4280 - rate << endl;
    }
  }
}
Problem p00217 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int main(void) {
  int n, a[10000], s, d, max, z, x[10000], i, j;
  while (1) {
    scanf("%d", &n);
    if (n == 0)
      break;
    for (i = 0; i < n; i++) {
      scanf("%d %d %d", &a[i], &s, &d);
      x[i] = s + d;
    }
    max = 0;
    for (i = 0; i < n; i++) {
      if (max < x[i]) {
        max = x[i];
        z = a[i];
      }
    }
    printf("%d %d\\n", z, max);
  }
  return 0;
}

Error: WA

Fixed submission:

#include <stdio.h>
int main(void) {
  int n, a[1000], s, d, max, z, x[1000], i, j;
  while (1) {
    scanf("%d", &n);
    if (n == 0)
      break;
    for (i = 0; i < n; i++) {
      scanf("%d %d %d", &a[i], &s, &d);
      x[i] = s + d;
    }
    max = 0;
    for (j = 0; j < n; j++) {
      if (max < x[i]) {
        max = x[i];
        z = a[i];
      }
    }
    printf("%d %d\\n", z, max);
  }
  return 0;
}
Problem p00217 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>

using namespace std;

int main() {
  int n;
  int num, pt;
  int d1, d2;

  while (scanf("%d", &n), n != 0) {
    int max_n, max_pt = 0;

    for (int i = 0; i < n; i++) {
      scanf("%d%d%d", &num, &d1, &d2);
      pt = d1 + d2;
      if (max_pt < pt) {
        max_n = num;
        max_pt = pt;
      }
    }
    cout << max_n << " " << max_pt << endl;
  }

  return (0);
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>

using namespace std;

typedef struct {
  int num;
  int pt;
} HOS;
int main() {
  HOS walk[10000], tmp;
  int n;
  int d1, d2;

  while (scanf("%d", &n), n != 0) {
    for (int i = 0; i < n; i++) {
      scanf("%d%d%d", &walk[i].num, &d1, &d2);
      walk[i].pt = d1 + d2;
    }

    for (int i = 0; i < n - 1; i++) {
      for (int j = n - 1; j > i; j--) {
        if (walk[j].pt > walk[j - 1].pt) {
          tmp = walk[j];
          walk[j] = walk[j - 1];
          walk[j - 1] = tmp;
        }
      }
    }

    printf("%d %d\\n", walk[0].num, walk[0].pt);
  }

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

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

typedef struct {
  int no;
  int walk;
} Patiant;

int main(void) {
  int n;
  while (cin >> n, n) {
    Patiant input, max;
    max.walk = -1;
    int inp, f, s;
    for (int i = 0; i < n; i++) {
      cin >> inp;
      input.no = inp;
      cin >> f >> s;
      input.walk = f + s;
      if (input.walk > max.walk)
        max = input;
    }
    cout << max.no << " " << max.walk << endl;
  }
}

Error: TLE

Fixed submission:

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

typedef struct {
  int no;
  int walk;
} Patiant;

int main(void) {
  int n;
  while (cin >> n, n) {
    Patiant patiant[10000];
    int inp, f, s;
    for (int i = 0; i < n; i++) {
      cin >> inp;
      patiant[i].no = inp;
      cin >> f >> s;
      patiant[i].walk = f + s;
      //			cout<<patiant[i].no<<" "<<patiant[i].walk<<endl;
    }
    for (int i = 0; i < n - 1; i++) {
      for (int j = 1; j < n; j++) {
        //				cout<<patiant[i].walk<<" "<<i<<"
        //"<<patiant[j].walk<<" "<<j<<endl;
        if (patiant[i].walk < patiant[j].walk) {
          Patiant tmp = patiant[i];
          patiant[i] = patiant[j];
          patiant[j] = tmp;
          //					cout<<i;
        }
      }
      //			cout<<endl;
    }

    //		for(int i = 0 ; i < n ; i ++)
    //				cout<<patiant[i].no<<" "<<patiant[i].walk<<endl;
    cout << patiant[0].no << " " << patiant[0].walk << endl;
  }
}
Problem p00217 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int a, b, c;
  while (cin >> a, a != 0) {
    int d[10000] = {}, sum[10000] = {};
    for (int i = 0; i < a; i++) {
      cin >> d[i] >> b >> c;
      sum[i] = b + c;
      for (int j = 0; j < 2; j++) {
        if (sum[0] < sum[i]) {
          swap(sum[i], sum[0]);
          swap(d[i], d[0]);
        }
      }
    }
    cout << d[0] << " " << sum[0] << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int a, b, c;
  while (cin >> a, a != 0) {
    int d[10000] = {}, sum[10000] = {};
    for (int i = 0; i < a; i++) {
      cin >> d[i] >> b >> c;
      sum[i] = b + c;
      for (int j = 0; j < a; j++) {
        if (sum[0] < sum[i]) {
          swap(sum[i], sum[0]);
          swap(d[i], d[0]);
        }
      }
    }
    cout << d[0] << " " << sum[0] << endl;
  }
  return 0;
}
Problem p00217 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
struct k {
  int bangou;
  int score;
};
int main() {
  int n;
  int d1, d2, b;
  k id[10001];
  while (cin >> n, n) {
    for (int i = 0; i < n; i++) {
      cin >> b >> d1 >> d2;
      id[i].bangou = b;
      id[i].score = (d1 + d2);
    }
    int max = 0;
    int ans_b;
    for (int i = 0; i < n; i++) {
      if (id[i].score > max) {
        max = id[i].score;
        ans_b = id[i].bangou;
      }
    }
    cout << ans_b << " " << max << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
struct k {
  int bangou;
  int score;
};
int main() {
  int n;
  int d1, d2, b;
  k id[1000];
  while (cin >> n, n) {
    for (int i = 0; i < n; i++) {
      cin >> b >> d1 >> d2;
      id[i].bangou = b;
      id[i].score = (d1 + d2);
    }
    int max = 0;
    int ans_b;
    for (int i = 0; i < n; i++) {
      if (id[i].score > max) {
        max = id[i].score;
        ans_b = id[i].bangou;
      }
    }
    cout << ans_b << " " << max << endl;
  }
  return 0;
}
Problem p00217 (C++) — buggy submission, verdict: Time Limit Exceeded

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

typedef struct {
  int num;
  int first;
  int second;
} Walk;

int main() {
  int n, max = -1, add;
  Walk people[10005];

  while (1) {
    scanf("%d", &n);
    if (n == 0)
      break;

    for (int i = 0; i < n; i++) {
      scanf("%d %d %d", &people[i].num, &people[i].first, &people[i].second);
      if (max < people[i].first + people[i].second) {
        max = people[i].first + people[i].second;
        add = i;
      }
    }
    printf("%d %d\\n", people[add].num, max);
    add = 0;
    max = -1;
  }

  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int w, sum = 0;
  while (1) {
    scanf("%d", &w);
    if (w == -1)
      break;
    if (w > 30) {
      sum += (w - 30) * 160;
      w = 30;
    }
    if (w > 20) {
      sum += (w - 20) * 140;
      w = 20;
    }
    if (w > 10) {
      sum += (w - 10) * 125;
    }
    printf("%d\\n", 4280 - (sum + 1150));
    sum = 0;
  }
  return 0;
}
Problem p00217 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <math.h>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <string>

using namespace std;

int main(void) {
  for (int u = 0; u < 50; u++) {
    long n;
    long id[10000], a[10000], b[10000];
    int p = -1;
    int q = 0;

    cin >> n;
    if (n == 0) {
      break;
    }

    for (long i = 0; i < n; i++) {
      cin >> id[i] >> a[i] >> b[i];
    }

    for (long i = 0; i < n; i++) {
      if (a[i] + b[i] > q) {
        p = 0;
        p = id[i];
        q = 0;
        q = a[i] + b[i];
      }
    }

    cout << p << " " << q << endl;
  }
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <math.h>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <string>

using namespace std;

int main(void) {
  for (int u = 0; u < 50; u++) {
    long n;
    long id[51], a[51], b[51];
    int p = -1;
    int q = 0;

    cin >> n;
    if (n == 0) {
      break;
    }

    for (long i = 0; i < n; i++) {
      cin >> id[i] >> a[i] >> b[i];
    }

    for (long i = 0; i < n; i++) {
      if (a[i] + b[i] > q) {
        p = 0;
        p = id[i];
        q = 0;
        q = a[i] + b[i];
      }
    }

    cout << p << " " << q << endl;
  }
}
Problem p00218 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int main(void) {
  int number, pm, pe, pj, temp;
  while (1) {
    scanf("%d", &number);
    if (number == 0) {
      break;
    }
    for (int i = number; i > 0; i--) {
      scanf("%d %d %d", &pm, &pe, &pj);
      if (pm == 100 || pe == 100 || pj == 100 || (pe + pm) / 2 >= 90 ||
          (pe + pm + pj) / 3 >= 80) {
        printf("A\\n");
      } else if ((pe + pm + pj) / 3 >= 70 ||
                 ((pe + pm + pj) / 3 >= 50 && (pe >= 80 || pm >= 80))) {
        printf("B\\n");
      } else {
        printf("C\\n");
      }
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <stdio.h>

int main(void) {
  int number, pm, pe, pj, temp;
  while (1) {
    scanf("%d", &number);
    for (int i = number; i > 0; i--) {
      scanf("%d %d %d", &pm, &pe, &pj);
      if (pm == 100 || pe == 100 || pj == 100 || (pe + pm) / 2 >= 90 ||
          (pe + pm + pj) / 3 >= 80) {
        printf("A\\n");
      } else if ((pe + pm + pj) / 3 >= 70 ||
                 ((pe + pm + pj) / 3 >= 50 && (pe >= 80 || pm >= 80))) {
        printf("B\\n");
      } else {
        printf("C\\n");
      }
    }
  }
  return 0;
}
Problem p00218 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n, a, b, c;
  vector<char> l;
  while (true) {
    cin >> n;
    if (n == 0) {
      break;
    } else {
      for (int i = 0; i < n; i++) {
        cin >> a >> b >> c;
        if (a == 100 || b == 100 || c == 100) {
          l.push_back('A');
        } else if (a + b >= 180) {
          l.push_back('A');
        } else if (a + b + c >= 240) {
          l.push_back('A');
        } else if (a + b + c >= 210) {
          l.push_back('B');
        } else if (a + b + c >= 150 && a >= 80) {
          l.push_back('B');
        } else if (a + b + c >= 150 && b >= 80) {
          l.push_back('B');
        } else
          l.push_back('C');
        a = 0;
        b = 0;
        c = 0;
      }
    }
  }
  for (int i = 0; i != l.size(); i++) {
    cout << l[i] << endl;
  }
}

Error: -11

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n, a, b, c;
  vector<char> l;
  while (true) {
    cin >> n;
    if (n == 0) {
      break;
    } else {
      for (int i = 0; i < n; i++) {
        cin >> a >> b >> c;
        if (a == 100 || b == 100 || c || 100) {
          l[i] = 'A';
        } else if (a + b >= 180) {
          l[i] = 'A';
        } else if (a + b + c >= 240) {
          l[i] = 'A';
        } else if (a + b + c >= 210) {
          l[i] = 'B';
        } else if (a + b + c >= 150 && a >= 80) {
          l[i] = 'B';
        } else if (a + b + c >= 150 && b >= 80) {
          l[i] = 'B';
        } else
          l[i] = 'C';
      }
    }
  }
  for (int i = 0; i != l.size(); i++) {
    cout << l[i] << endl;
  }
}
Problem p00218 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(void) {
  vector<vector<int>> p(10000, vector<int>(3));
  vector<char> ans(10000);
  int n;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> p[i][0] >> p[i][1] >> p[i][2];
      if (p[i][0] == 100 || p[i][1] == 100 || p[i][2] == 100)
        ans[i] = 'A';
      else if (90 * 2 <= p[i][0] + p[i][1])
        ans[i] = 'A';
      else if (80 * 3 <= p[i][0] + p[i][1] + p[i][2])
        ans[i] = 'A';
      else if (70 * 3 <= p[i][0] + p[i][1] + p[i][2])
        ans[i] = 'B';
      else if (50 * 3 <= p[i][0] + p[i][1] + p[i][2] &&
               (80 <= p[i][0] || 80 <= p[i][1]))
        ans[i] = 'B';
      else
        ans[i] = 'C';
    }
    for (int i = 0; i < n; i++)
      cout << ans[i] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(void) {
  vector<vector<int>> p(10000, vector<int>(3));
  vector<char> ans(10000);
  int n;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> p[i][0] >> p[i][1] >> p[i][2];
      if (p[i][0] == 100 || p[i][1] == 100 || p[i][2] == 100)
        ans[i] = 'A';
      else if (90 * 2 <= p[i][0] + p[i][1])
        ans[i] = 'A';
      else if (80 * 3 <= p[i][0] + p[i][1] + p[i][2])
        ans[i] = 'A';
      else if (70 * 3 <= p[i][0] + p[i][1] + p[i][2])
        ans[i] = 'B';
      else if (50 * 3 <= p[i][0] + p[i][1] + p[i][2] &&
               (80 <= p[i][0] || 80 <= p[i][1]))
        ans[i] = 'B';
      else
        ans[i] = 'C';
    }
    for (int i = 0; i < n; i++)
      cout << ans[i] << endl;
    p.clear();
    ans.clear();
  }
  return 0;
}
Problem p00218 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
int main(void) {
  int n, pm, pe, pj, s, i;
  while (1) {
    scanf("%d", &n);
    if (n == 0)
      break;
    for (i = 0; i < n; i++) {
      scanf("%d%d%d", &pm, &pe, &pj);
      s = (pm + pe + pj) / 3;
      if (pm == 100 || pe == 100 || pj == 100)
        printf("A\\n");
      else if ((pm + pe) / 2 >= 90)
        printf("A\\n");
      else if (s >= 80)
        printf("A\\n");
      else if (s >= 70)
        printf("B\\n");
      else if (s >= 50 && (pm >= 80 || pe >= 80))
        printf("B\\n");
      else
        printf("C\\n");
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
int main(void) {
  int a, b, i;
  while (1) {
    scanf("%d", &a);
    if (a == -1)
      break;
    b = 0;
    if (a <= 10) {
      b = 1150;
    } else if (a <= 20) {
      b = 1150;
      for (i = 0; i < a - 10; i++) {
        b += 125;
      }
    } else if (a <= 30) {
      b = 2400;
      for (i = 0; i < a - 20; i++) {
        b += 140;
      }
    } else if (a > 30) {
      b = 3800;
      for (i = 0; i < a - 30; i++) {
        b += 160;
      }
    }
    printf("%d\\n", 4280 - b);
  }
  return 0;
}