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

#include <iostream>
using namespace std;

struct node {
  int n, mn, mt, cn[21], t[21];
};
node d[21];

int search(int fr, int to, int a) {
  int i, k, m = 0, mn = 0, mt = 0;
  for (i = 0; i < d[to].n; i++) {
    if (d[to].cn[i] == fr || d[d[to].cn[i]].n == 1)
      continue;
    k = search(to, d[to].cn[i], d[to].t[i]);
    if (k >= m) {
      mn = d[to].cn[i];
      mt = d[to].t[i];
      m = k;
    }
  }
  d[to].mn = mn;
  d[to].mt = mt;
  return m + a;
}

int main() {
  int i, n, a, b, t, g, s;
  while (cin >> n && n > 0) {
    g = 0;
    for (i = 1; i <= n; i++)
      d[i].n = d[i].mn = 0;
    for (i = 0; i < n - 1; i++) {
      cin >> a >> b >> t;
      g = g + t * 2;
      d[a].t[d[a].n] = d[b].t[d[b].n] = t;
      d[a].cn[d[a].n++] = b;
      d[b].cn[d[b].n++] = a;
    }
    for (i = 2; i <= n; i++)
      if (d[i].n == 1)
        g -= d[i].t[0] * 2;
    search(1, 1, 0);
    s = 1;
    while (d[s].mn > 0) {
      g -= d[s].mt;
      s = d[s].mn;
    }
    cout << g << endl;
  }
  return 0;
}

Error: 1

Fixed submission:

#include <iostream>
using namespace std;

struct node {
  int n, mn, cn[22], t[22];
};

int main() {
  int i, j, n, a, b, t, g, s, m, nx, fr;
  node d[22];
  while (cin >> n && n > 0) {
    g = 0;
    for (i = 0; i < n - 1; i++) {
      cin >> a >> b >> t;
      g = g + t * 2;
      d[a].t[0] = 1;
      d[b].t[0] = 1;
    }
    cout << g << endl;
  }
  return 1;
}
Problem p00235 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const double EPS = 1e-10;
const int INF = 1001001001;

struct Edge {
  Edge(int s, int d, int c) : src(s), dst(d), cost(c) {}
  int src, dst, cost;
};

vector<Edge> G[20];
int cost[20];
int f(int now, int pre, int dist) {
  cost[now] = dist;
  int sum = 0;
  rep(i, G[now].size()) {
    Edge next = G[now][i];
    if (next.dst != pre && G[next.dst].size() > 1)
      sum += f(next.dst, now, dist + next.cost) + next.cost;
  }
  return sum;
}

int main() {
  int n;
  while (scanf("%d", &n), n) {
    fill(cost, cost + n, 0);
    rep(i, n) G[i].clear();
    rep(i, n - 1) {
      int a, b, c;
      scanf("%d%d%d", &a, &b, &c);
      --a;
      --b;
      G[a].push_back(Edge(a, b, c));
      G[b].push_back(Edge(b, a, c));
    }
    int sum = f(0, -1, 0);
    printf("%d\\n", sum * 2 - *max_element(cost, cost + n));
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const double EPS = 1e-10;
const int INF = 1001001001;

struct Edge {
  Edge(int s, int d, int c) : src(s), dst(d), cost(c) {}
  int src, dst, cost;
};

vector<Edge> G[20];
int cost[20];
int f(int now, int pre, int dist) {
  cost[now] = dist;
  int sum = 0;
  rep(i, G[now].size()) {
    Edge next = G[now][i];
    if (next.dst != pre && G[next.dst].size() > 1)
      sum += f(next.dst, now, dist + next.cost) + next.cost;
  }
  return sum;
}

int main() {
  int n;
  while (scanf("%d", &n), n) {
    fill(cost, cost + n, 0);
    rep(i, n - 1) {
      int a, b, c;
      scanf("%d%d%d", &a, &b, &c);
      --a;
      --b;
      G[a].push_back(Edge(a, b, c));
      G[b].push_back(Edge(b, a, c));
    }
    int sum = f(0, -1, 0);
    printf("%d\\n", sum * 2 - *max_element(cost, cost + n));
  }
  return 0;
}
Problem p00235 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

vector<vector<int>> graph(20);
int bridges[20][20];
bool used[20][20];

int calc_sum(int from) {
  int sum = 0;

  for (int i = 0; i < graph[from].size(); ++i) {
    int to = graph[from][i];
    if (graph[to].size() == 1)
      continue;
    if (used[from][to])
      continue;
    used[to][from] = true;
    sum += bridges[from][to] * 2 + calc_sum(to);
  }

  return sum;
}

int calc_max(int from) {
  int ma = 0;

  for (int i = 0; i < graph[from].size(); ++i) {
    int to = graph[from][i];
    if (graph[to].size() == 1)
      continue;
    if (used[from][to])
      continue;
    used[to][from] = true;
    ma = max(ma, bridges[from][to] + calc_max(to));
  }

  return ma;
}

int main() {
  int n;
  while (cin >> n, n) {
    memset(bridges, 0, sizeof(bridges));
    for (int i = 0; i < 20; ++i)
      graph[i].clear();
    for (int i = 0; i < n - 1; ++i) {
      int a, b, t;
      cin >> a >> b >> t;
      a--;
      b--;
      bridges[a][b] = bridges[b][a] = t;
      graph[a].push_back(b);
      graph[b].push_back(a);
    }

    memset(used, 0, sizeof(used));
    int sum = calc_sum(0);
    memset(used, 0, sizeof(used));
    int ma = calc_max(0);

    cout << sum - ma << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

vector<vector<int>> graph(20);
int bridges[20][20];
bool used[20][20];

int calc_sum(int from) {
  int sum = 0;

  for (int i = 0; i < graph[from].size(); ++i) {
    int to = graph[from][i];
    if (graph[to].size() == 1)
      continue;
    if (used[from][to])
      continue;
    used[to][from] = true;
    sum += bridges[from][to] * 2 + calc_sum(to);
  }

  return sum;
}

int calc_max(int from) {
  int ma = 0;

  for (int i = 0; i < graph[from].size(); ++i) {
    int to = graph[from][i];
    if (graph[to].size() == 1)
      continue;
    if (used[from][to])
      continue;
    used[to][from] = true;
    ma = max(ma, bridges[from][to] + calc_max(to));
  }

  return ma;
}

int main() {
  int n;
  while (cin >> n, n) {
    memset(bridges, 0, sizeof(bridges));
    graph.clear();
    for (int i = 0; i < n - 1; ++i) {
      int a, b, t;
      cin >> a >> b >> t;
      a--;
      b--;
      bridges[a][b] = bridges[b][a] = t;
      graph[a].push_back(b);
      graph[b].push_back(a);
    }

    memset(used, 0, sizeof(used));
    int sum = calc_sum(0);
    memset(used, 0, sizeof(used));
    int ma = calc_max(0);

    cout << sum - ma << endl;
  }
}
Problem p00236 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int w, h;
bool grid[10][10], vis[10][10];
int block[10][10];
int sy, sx, n;
int dy[] = {-1, 0, 1, 0}, dx[] = {0, 1, 0, -1};
int b[] = {3, 5, 6, 9, 10, 12};

int dfs(int y, int x) {
  if (vis[y][x])
    return 0;
  vis[y][x] = true;

  int res = 1;
  for (int i = 0; i < 4; i++) {
    if ((block[y][x] >> i) & 1) {
      int ty = y + dy[i], tx = x + dx[i];
      if (ty < 0 || tx < 0 || ty >= h || tx >= w)
        continue;
      res += dfs(ty, tx);
    }
  }
  return res;
}

bool rec(int y, int x) {
  if (y == h) {
    for (int i = 0; i < h; i++)
      for (int j = 0; j < w; j++)
        vis[i][j] = false;
    return dfs(sy, sx) == n;
  }
  if (grid[y][x]) {
    return (x + 1 >= w) ? rec(y + 1, 0) : rec(y, x + 1);
  }

  bool res;
  for (int i = 0; i < 6; i++) {
    if (b[i] & 1) {
      if (y - 1 < 0 || grid[y - 1][x] || !((block[y - 1][x] >> 2) & 1))
        continue;
    } else {
      if (y && !grid[y - 1][x] && (block[y - 1][x] >> 2) & 1)
        continue;
    }
    if ((b[i] >> 1) & 1) {
      if (x + 1 >= w || grid[y][x + 1])
        continue;
    }
    if ((b[i] >> 2) & 1) {
      if (y + 1 >= h || grid[y + 1][x])
        continue;
    }
    if ((b[i] >> 3) & 1) {
      if (x - 1 < 0 || grid[y][x - 1] || !((block[y][x - 1] >> 1) & 1))
        continue;
    } else {
      if (x && !grid[y][x - 1] && (block[y][x - 1] >> 1) & 1)
        continue;
    }

    block[y][x] = b[i];
    res = (x + 1 >= w) ? rec(y + 1, 0) : rec(y, x + 1);
    if (res)
      return true;
  }
  return false;
}

int main() {
  while (cin >> w >> h, (w || h)) {
    sy = sx = -1;
    n = 0;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cin >> grid[i][j];
        if (!grid[i][j] && sy < 0) {
          sy = i;
          sx = j;
        }
        n += grid[i][j];
        block[i][j] = 0;
      }
    }
    n = h * w - n;

    cout << ((n && rec(0, 0)) ? "Yes" : "No") << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int w, h;
bool grid[10][10];
int sy, sx;
int n;
int dy[] = {-1, 0, 1, 0}, dx[] = {0, 1, 0, -1};

bool rec(int y, int x, int cnt) {
  if (y == sy && x == sx && cnt == n)
    return true;
  if (grid[y][x])
    return false;
  grid[y][x] = true;

  bool res = false;
  for (int i = 0; i < 4; i++) {
    int ty = y + dy[i], tx = x + dx[i];
    if (ty < 0 || tx < 0 || h <= ty || w <= tx)
      continue;
    res |= rec(ty, tx, cnt + 1);
  }
  grid[y][x] = false;
  return res;
}

int main() {
  while (cin >> w >> h, (w || h)) {
    sy = sx = -1;
    n = 0;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cin >> grid[i][j];
        if (!grid[i][j] && sy < 0) {
          sy = i;
          sx = j;
        }
        if (!grid[i][j])
          n++;
      }
    }

    cout << ((n && (n == 1 || rec(sy, sx, 0))) ? "Yes" : "No") << endl;
  }
}
Problem p00238 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
int main(void) {
  int t, n, s, f, i, z;
  scanf("%d", &t);
  while (t != 0) {
    z = 0;
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
      scanf("%d %d", &s, &f);
      z += f - s;
    }
    if (z >= t) {
      printf("OK\\n");
    } else {
      printf("%d\\n", t - z);
    }
    scanf("%d", &t);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
int main(void) {
  int t, n, s, f, i, z;
  scanf("%d", &t);
  scanf("%d", &n);
  while (n != 0) {
    for (i = 0; i < n; i++) {
      scanf("%d %d", &s, &f);
      z += f - s;
    }
    if (z >= 10) {
      printf("OK\\n");
    } else {
      printf("2\\n");
    }
    scanf("%d", &n);
  }
  return 0;
}
Problem p00238 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int a, n, t1, t2;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    cin >> a;
    for (int i = 0; i < a; i++) {
      cin >> t1 >> t2;
      n -= t2 - t1;
    }
    if (n <= 0)
      cout << "OK" << endl;
    else
      cout << n << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int a, n, t1, t2;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    cin >> a;
    for (int i = 0; i < a; i++) {
      cin >> t1 >> t2;
      n -= t2 - t1;
      if (n <= 0) {
        cout << "OK" << endl;
        break;
      }
    }
    if (n > 0) {
      cout << n << endl;
    }
  }
}
Problem p00238 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int main() {

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

    scanf("%d", &N);
    int s, f;
    for (int i = 0; i < N; i++) {
      scanf("%d %d", &s, &f);
      f -= s;
      G -= f;
      // if(G<=0)break;
    }
    if (G <= 0)
      printf("OK\\n");
    else
      printf("%d\\n", G);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <stdio.h>
using namespace std;

int main() {

  int n;
  while (1) {

    scanf("%d", &n);
    if (n == 0)
      break;
    int y, t, b;

    double s = 0, max = 0, r;
    int MM = 0;
    scanf("%d", &y);
    for (int i = 0; i < n; i++) {
      scanf("%d %lf %d", &b, &r, &t);

      if (t == 1) {
        s = 1 + y * r / 100;
      } else {
        double s1 = 1 + r / 100;
        s = s1;

        for (int j = 1; j < y; j++) {
          s = s * s1;
        }
      }

      if (s > max) {
        max = s;
        MM = b;
      }
    }
    printf("%d\\n", MM);
  }
  return 0;
}
Problem p00238 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int main() {
  int T, N, S, A, B;

  while (true) {
    cin >> T;

    if (T == 0) {
      break;
    }

    cin >> N;
    S = 0;

    for (int i = 0; i < N; i++) {
      cin >> A >> B;

      S += B - A;
    }

    if (S >= T) {
      cout << "OK" << endl;
    } else {
      cout << T - S << endl;
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
int t, n, s, f, i, q;
int main() {
  while (1) {
    scanf("%d", &t);
    if (!t) {
      break;
    }
    scanf("%d", &n);
    q = 0;
    for (i = 0; i < t; i++) {
      scanf("%d%d", &s, &f);
      q += f - s;
    }
    if (q < n) {
      printf("%d\\n", n - q);
    } else {
      printf("OK\\n");
    }
  }
}
Problem p00238 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, c, a, b;
  while (cin >> n, n) {
    cin >> c;
    int y = 0;
    for (i = 0; i < c; i++) {
      cin >> a >> b;
      y += b - a;
    }
    if (y >= n)
      cout << "OK" << endl;
    else
      cout << n - y << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, c, a, b;
  while (cin >> n, n) {
    cin >> c;
    int y = 0;
    for (i = 0; i < c; c++) {
      cin >> a >> b;
      y += b - a;
    }
    if (y >= n)
      cout << "OK" << endl;
    else
      cout << n - y << endl;
  }
}
Problem p00238 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int t, n, s, f, sum;

  while (cin >> t && t) {
    cin >> n;
    sum = 0;
    for (int i = 0; i < n; i++) {
      cin >> s >> f;
      sum += (f - s);
    }

    if (sum >= t) {
      cout << "OK" << endl;
    } else {
      cout << t - sum << endl;
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int t, n, s, f, sum;
  cin >> t;

  while (cin >> n, n) {
    for (int i = 0; i < n; i++) {
      cin >> s >> f;
      sum += (f - s);
    }

    if (sum >= t) {
      cout << "OK" << endl;
    } else {
      cout << t - sum;
    }
  }

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

#include <stdio.h>
int main(void) {
  int n, t, i, k, j, g, s, r, a;
  while (1) {
    scanf("%d", &t);
    if (t == 0)
      break;
    scanf("%d", &n);
    g = 0;
    for (i = 0; i < n; i++) {
      scanf("%d %d", &a, &s);
      k = s - a;
      g += k;
    }
    if (g >= t) {
      printf("OK\\n");
    }
    if (g < t) {
      r = t - g;
      printf("%d\\n", r);
    }
    k = 0;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>
int main(void) {
  int n, t, i, k, cnt, x[10], j, g, s, r, a;
  cnt = 0;
  g = 0;
  while (1) {
    scanf("%d", &t);
    if (t == 0)
      break;
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
      scanf("%d %d", &a, &s);
      k = s - a;
      g += k;
    }
    if (g >= t) {
      x[cnt] = 0;
    }
    if (g < t) {
      r = t - g;
      x[cnt] = r;
    }
    k = 0;
    g = 0;
    cnt++;
  }
  for (j = 0; j < n; j++) {
    if (x[j] == 0) {
      printf("OK\\n");
    } else {
      printf("%d\\n", x[j]);
    }
  }
  return 0;
}
Problem p00238 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
int main(void) {
  int y, t, n, i, s, f, z, x;
  while (1) {
    scanf("%d", &t);
    if (t == 0)
      break;
    scanf("%d", &n);
    z = 0;
    for (i = 0; i < n; i++) {
      scanf("%d %d", &s, &f);
      x = f - s;
      z += x;
    }
    if (z >= t) {
      printf("OK\\n");
    }
    if (z < t) {
      y = t - z;
      printf("%d\\n", y);
    }
    x = 0;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
int main(void) {
  int t, n, i, s, f, z;
  while (1) {
    scanf("%d", &t);
    if (t == 0)
      break;
    scanf("%d", &n);
    z = 0;
    //		printf("%d\\n",n);
    for (i = 0; i < n; i++) {
      scanf("%d &d", &s, &f);
      z = z + (f - s);
    }
    if (z >= t) {
      printf("OK\\n");
    }
    if (z < t) {
      printf("%d\\n", t - z);
    }
  }
  return 0;
}
Problem p00238 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int main() {
  int a, b, i;
  int aa, bb;
  int time = 0, sa;
  while (1) {
    cin >> a;
    if (a == 0)
      break;
    cin >> b;
    for (i = 0; i < b; i++) {
      cin >> aa >> bb;
      sa = bb - aa;
      time = time + sa;
    }
    if (time >= a) {
      cout << "OK" << endl;
    } else if (time < a) {
      cout << a - time << endl;
    }

    time = 0;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int a, b, i;
  int aa[i], bb[i];
  int time = 0, sa;
  while (1) {
    cin >> a;
    if (a == 0)
      break;
    cin >> b;
    for (i = 0; i < b; i++) {
      cin >> aa[i] >> bb[i];
      sa = bb[i] - aa[i];
      time = time + sa;
    }
    if (time >= a)
      cout << "OK" << endl;
    if (time < a)
      cout << a - time << endl;
    time = 0;
  }
  return 0;
}
Problem p00238 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int main(void) {
  int t, n, s, f;

  while (scanf("%d", &t), t) {
    scanf("%d", &n);
    while (n--) {
      scanf("%d %d", &s, &f);
      t -= (f - s);
    }
    if (t <= 0)
      puts("OK");
    else
      printf("%d\\n", t);
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <stdio.h>

int main(void) {
  int t, n, s, f;

  while (scanf("%d", &t), t) {
    scanf("%d", &n);
    for (; n >= 0; n--) {
      scanf("%d %d", &s, &f);
      t -= (f - s);
    }
    if (t < 0)
      puts("OK");
    else
      printf("%d\\n", t);
  }
  return 0;
}
Problem p00238 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main(void) {
  while (true) {
    int n, m, p;
    p = 0;
    cin >> n;
    if (n == 0) {
      break;
    }
    cin >> m;
    while (m > 0) {
      int s, q;
      cin >> s >> q;
      p += q - s;
      m--;
    }
    if (p >= n) {
      cout << "OK" << endl;
    } else {
      cout << n - p << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main(void) {
  while (true) {
    int n, m, p;
    p = 0;
    cin >> n;
    if (n = 0) {
      break;
    }
    cin >> m;
    while (m > 0) {
      int s, q;
      cin >> s >> q;
      p += q - s;
      m--;
    }
    if (p >= n) {
      cout << "OK" << endl;
    } else {
      cout << n - p;
    }
  }
  return 0;
}
Problem p00238 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int t, n, s, f, r;

  cin >> t;
  while (t) {
    r = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> s >> f;
      r += (f - s);
    }
    if (r >= t)
      cout << "OK\\n";
    else
      cout << t - r << endl;
    cin >> t;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int t, n, s, f, r = 0;
  cin >> n;
  while (n) {
    cin >> t;
    for (int i = 0; i < n; i++) {
      cin >> s >> f;
      r += (f - s);
    }
    if (r >= t)
      cout << "OK\\n";
    else
      cout << t - r << endl;
    cin >> n;
  }
  return 0;
}
Problem p00239 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {

  int n;

  while (true) {

    int i[1000], p[1000], q[1000], r[1000];

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

    for (int j = 0; j < n; j++) {

      cin >> i[j] >> p[j] >> q[j] >> r[j];
    }
    int P, Q, R, C;
    int sp = 0, sq = 0, sr = 0;
    int cal[1000];
    int count = 0;

    cin >> P >> Q >> R >> C;

    for (int j = 0; j < n; j++) {
      sp = p[j] * 4;
      sq = q[j] * 9;
      sr = r[j] * 4;
      cal[j] = sp + sq + sr;

      if (P >= p[j] && Q >= q[j] && R >= r[j] && C >= cal[j]) {
        count++;
        cout << i[j] << endl;
      }
    }
    if (count == 0)
      cout << "NA" << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

  while (true) {
    int n, s, f;
    int sum = 0;

    cin >> t;

    if (t == 0)
      break;

    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> s >> f;

      sum += f - s;
    }

    if (sum >= t)
      cout << "OK" << endl;

    else if (sum < t)
      cout << t - sum << endl;
  }
  return 0;
}
Problem p00239 (C++) — buggy submission, verdict: Time Limit Exceeded

// 2014/05/23 Tazoe

#include <iostream>
using namespace std;

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

    if (n == 0)
      break;

    int i[1000], p[1000], q[1000], r[1000];
    for (int j = 0; j < n; j++) {
      cin >> i[j] >> p[j] >> q[j] >> r[j];
    }

    int P, Q, R, C;
    cin >> P >> Q >> R >> C;

    bool flg = false;

    for (int j = 0; j < n; j++) {
      if (p[j] <= P && q[j] <= Q && r[j] <= R &&
          4 * p[j] + 9 * q[j] + 4 * r[j] <= C) {
        cout << i[j] << endl;
        flg = true;
      }
    }

    if (!flg) {
      cout << "NA" << endl;
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

// 2014/05/23 Tazoe

#include <iostream>
using namespace std;

int main() {
  while (true) {
    int t;
    cin >> t;

    if (t == 0)
      break;

    int n;
    cin >> n;

    int sum = 0;

    for (int i = 0; i < n; i++) {
      int s, f;
      cin >> s >> f;

      sum += (f - s);
    }

    if (sum >= t) {
      cout << "OK" << endl;
    } else {
      cout << t - sum << endl;
    }
  }

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

#include <iostream>
using namespace std;

int main() {
  int N;
  int s[1000], h[1000], L[1000], C[1000];
  while (cin >> N) {
    if (N == 0)
      break;
    for (int i = 0; i < N; i++) {
      cin >> s[i] >> h[i] >> L[i] >> C[i];
    }
    int P, Q, R, c;
    int a = 0;
    cin >> P >> Q >> R >> c;
    for (int i = 0; i < N; i++) {
      if ((h[i] <= P) && (L[i] <= Q) && (C[i] <= R) &&
          ((h[i] * 4 + L[i] * 9 + C[i] * 4) <= c)) {
        cout << s[i] << endl;
        a = 1;
      }
    }
    if (a == 0)
      cout << "NA" << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int N;
  int s[100], h[100], L[100], C[100];
  while (cin >> N) {
    if (N == 0)
      break;
    for (int i = 0; i < N; i++) {
      cin >> s[i] >> h[i] >> L[i] >> C[i];
    }
    int P, Q, R, c;
    int a = 0;
    cin >> P >> Q >> R >> c;
    for (int i = 0; i < N; i++) {
      if ((h[i] <= P) && (L[i] <= Q) && (C[i] <= R) &&
          ((h[i] * 4 + L[i] * 9 + C[i] * 4) <= c)) {
        cout << s[i] << endl;
        a = 1;
      }
    }
    if (a == 0)
      cout << "NA" << endl;
  }
  return 0;
}