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

#include <iostream>
#define N 15
using namespace std;
void func(int, int);
int jump(int, int);
int X, Y, data[N][N], memo[N][N];
int main() {
  while (1) {
    cin >> X >> Y;
    if (X == 0 && Y == 0)
      break;
    for (int i = 0; i < Y; i++)
      for (int j = 0; j < X; j++)
        cin >> data[i][j], memo[i][j] = 0;
    for (int i = 0; i < X; i++)
      if (data[0][i] == 0)
        func(0, i);
    int cnt = 0;
    for (int i = 0; i < X; i++)
      cnt += memo[0][i];
    cout << cnt << endl;
  }
  return 0;
}
void func(int y, int x) {
  if (y == Y - 1) {
    memo[Y - 1][x] = 1;
    return;
  }
  if (0 <= x - 1 && data[y + 1][x - 1] == 0) {
    if (memo[y + 1][x - 1] == 0)
      func(y + 1, x - 1);
    memo[y][x] += memo[y + 1][x - 1];
  }
  if (x + 1 < X && data[y + 1][x + 1] == 0) {
    if (memo[y + 1][x + 1] == 0)
      func(y + 1, x + 1);
    memo[y][x] += memo[y + 1][x + 1];
  }
  if (data[y + 1][x] == 0) {
    if (memo[y + 1][x] == 0)
      func(y + 1, x);
    memo[y][x] += memo[y + 1][x];
  }
  if (data[y + 1][x] == 2) {
    int r = jump(y + 1, x);
    if (r == -2)
      memo[y][x] += 1;
    else if (r != -1) {
      if (memo[r][x] == 0)
        func(r, x);
      memo[y][x] += memo[r][x];
    }
  }
  if (memo[y][x] == 0)
    data[y][x] = 1;
}
int jump(int y, int x) {
  while (1) {
    y += 2;
    if (y > Y - 1)
      return -2;
    if (data[y][x] == 1)
      break;
    if (y == Y - 1)
      return -2;
    if (data[y][x] == 0)
      return y;
  }
  return -1;
}

Error: TLE

Fixed submission:

#include <iostream>
#define N 15
using namespace std;
int data[N][N];
void func(int, int);
int Cnt(int, int);
int X, Y, cnt, memo[N][N];
int main() {
  while (1) {
    cin >> X >> Y;
    if (X == 0 && Y == 0)
      break;
    for (int i = 0; i < Y; i++)
      for (int j = 0; j < X; j++)
        cin >> data[i][j];
    cnt = 0;
    for (int i = 0; i < Y; i++)
      for (int j = 0; j < X; j++)
        memo[i][j] = -1;
    for (int i = 0; i < X; i++) {
      if (data[0][i] == 0)
        func(0, i);
    }
    cout << cnt << endl;
  }
  return 0;
}
void func(int y, int x) {
  if (y >= Y - 1) {
    cnt++;
    memo[Y - 1][x] = 1;
    return;
  } else
    memo[Y - 1][x] = 0;
  if (y + 1 < Y && x + 1 < X && data[y + 1][x + 1] == 0)
    func(y + 1, x + 1);
  if (y + 1 < Y && x - 1 >= 0 && data[y + 1][x - 1] == 0)
    func(y + 1, x - 1);
  if (y + 1 < Y && data[y + 1][x] == 2) {
    int r = Cnt(y, x);
    if (r != -1) {
      if (memo[y + 1][x] != -1)
        memo[y][x] += memo[y + 1][x];
      func(r, x);
      if (memo[y + 1][x] != -1)
        memo[y][x] += memo[y + 1][x];
    } else
      return;
  }
  if (y + 1 < Y && data[y + 1][x] == 0)
    func(y + 1, x);
}
int Cnt(int y, int x) {
  y += 3;
  while (1) {
    if (y >= Y - 1) {
      if (y > Y - 1)
        cnt++;
      else if (y == Y - 1 && data[y][x] != 1)
        cnt++;
      break;
    }
    if (data[y][x] == 1)
      break;
    if (data[y][x] == 2)
      y += 2;
    if (data[y][x] == 0)
      return y;
  }
  return -1;
}
Problem p00203 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int main() {
  int x, y;
  while (cin >> x >> y, x | y) {
    vvi field(y, vi(x));
    REP(i, y) {
      REP(j, x) { cin >> field[i][j]; }
    }
    vvi dp(y, vi(x, 0));
    REP(i, y) {
      REP(j, x) {
        if (i == 0 && field[i][j] == 0) {
          dp[i][j] = 1;
        }
        if (i < y - 1 && field[i][j] == 0) {
          if (j > 0 && field[i + 1][j - 1] == 0) {
            dp[i + 1][j - 1] += dp[i][j];
          }
          if (j < x - 1 && field[i + 1][j + 1] == 0) {
            dp[i + 1][j + 1] += dp[i][j];
          }
          if (field[i + 1][j] != 1) {
            dp[i + 1][j] += dp[i][j];
          }
        }
        if (i < y - 2 && field[i][j] == 2) {
          if (field[i + 2][j] != 1) {
            dp[i + 2][j] += dp[i][j];
          }
        }
      }
    }
    int result = 0;
    REP(i, x) {
      result += dp[y - 1][i];
      if (y >= 2 && field[y - 2][i] == 2) {
        result += dp[y - 2][i];
      }
    }
    cout << result << endl;
  }
}

Error: 0

Fixed submission:

#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int main() {
  int x, y;
  while (cin >> x >> y, x | y) {
    vvi field(y, vi(x));
    REP(i, y) {
      REP(j, x) { cin >> field[i][j]; }
    }
    vvi dp(y, vi(x, 0));
    REP(i, y) {
      REP(j, x) {
        if (i == 0 && field[i][j] == 0) {
          dp[i][j] = 1;
        }
        if (i < y - 1 && field[i][j] == 0) {
          if (j > 0 && field[i + 1][j - 1] == 0) {
            dp[i + 1][j - 1] += dp[i][j];
          }
          if (j < x - 1 && field[i + 1][j + 1] == 0) {
            dp[i + 1][j + 1] += dp[i][j];
          }
          if (field[i + 1][j] != 1) {
            dp[i + 1][j] += dp[i][j];
          }
        }
        if (i < y - 2 && field[i][j] == 2) {
          if (field[i + 2][j] != 1) {
            dp[i + 2][j] += dp[i][j];
          }
        }
      }
    }
    int result = 0;
    REP(i, x) {
      result += dp[y - 1][i];
      if (field[y - 2][i] == 2) {
        result += dp[y - 2][i];
      }
    }
    cout << result << endl;
  }
  return 0;
}
Problem p00205 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
int main() {
  while (1) {
    int s[6], g[4] = {0}, n = -2, v = 0, i;
    for (i = 5; i; i--) {
      std::cin >> s[i];
      if (!s[5])
        goto l;
      if (!g[s[i]]) {
        n++;
        g[s[i]] = 1;
        if (v - 1 == s[i] % 3 || !v)
          v = s[i];
      }
    }
    for (i = 5; i; i--)
      std::cout << (!n ? (v == s[i] ? 1 : 2) : 3) << "\\n";
  }
l:;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
int main() {
  while (1) {
    int s[6], g[4] = {0}, n = -2, v = 0, i;
    for (i = 5; i; i--) {
      std::cin >> s[i];
      if (!*s)
        goto l;
      if (!g[s[i]]) {
        n++;
        g[s[i]] = 1;
        if (v - 1 == s[i] % 3 || !v)
          v = s[i];
      }
    }
    for (i = 5; i; i--)
      std::cout << (!n ? (v == s[i] ? 1 : 2) : 3) << "\\n";
  }
l:;
  return 0;
}
Problem p00205 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
  while (true) {
    int cur = 0, d[5];
    rep(i, 5) {
      if (cin >> d[i])
        d[i]--, cur |= (1 << d[i]);
      else
        return 0;
    }
    if (__builtin_popcount(cur) == 2) {
      rep(i, 5) cout << 2 - !!count(d, d + 5, (d[i] + 1) % 3) << endl;
    } else {
      rep(i, 5) cout << 3 << endl;
    }
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
  while (true) {
    int cur = 0, d[5];
    rep(i, 5) cin >> d[i], d[i]--, cur |= (1 << d[i]);
    if (__builtin_popcount(cur) == 2) {
      rep(i, 5) cout << 2 - !!count(d, d + 5, (d[i] + 1) % 3) << endl;
    } else {
      rep(i, 5) cout << 3 << endl;
    }
  }
}
Problem p00205 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i, n) for (i = 0; i < n; i++)
#define loop(i, a, n) for (i = a; i < n; i++)
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)

typedef vector<int> vi;
typedef pair<int, int> pii;
int main(void) {
  int i, j;
  vi hand(5);
  while (1) {
    vi n(3, 0);
    cin >> hand[0];
    if (hand[0] == 0)
      break;
    hand[0]--;
    n[hand[0]]++;
    rep(i, 4) {
      cin >> hand[1 + i];
      hand[1 + i]--;
      n[hand[1 + i]]++;
    }
    if (n[0] && n[1] && n[2])
      rep(i, 5) cout << "3" << endl;
    else if (n[0] == 5 || n[1] == 5 || n[2] == 5)
      rep(i, 5) cout << "3" << endl;
    else if (n[0] && n[1]) // gu choki
      rep(i, 5) if (hand[i]) cout << "2" << endl;
    else
      cout << "1" << endl;
    else if (n[0] && n[2]) // gu pa
        rep(i, 5) if (hand[i]) cout
        << "1" << endl;
    else cout << "2" << endl;
    else rep(i, 5) if (hand[i] == 1) cout << "1" << endl;
    else cout << "2" << endl;
  }
}

Error: -6
double free or corruption (out)


Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i, n) for (i = 0; i < n; i++)
#define loop(i, a, n) for (i = a; i < n; i++)
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)

typedef vector<int> vi;
typedef pair<int, int> pii;
int main(void) {
  int i, j;
  vi hand(5);
  while (scanf("%d", &hand[0]) != EOF) {
    vi n(3, 0);
    hand[0]--;
    n[hand[0]]++;
    rep(i, 4) {
      cin >> hand[1 + i];
      hand[1 + i]--;
      n[hand[1 + i]]++;
    }
    if (n[0] && n[1] && n[2])
      rep(i, 5) cout << "3" << endl;
    else if (n[0] == 5 || n[1] == 5 || n[2] == 5)
      rep(i, 5) cout << "3" << endl;
    else if (n[0] && n[1]) // gu choki
      rep(i, 5) if (hand[i]) cout << "2" << endl;
    else
      cout << "1" << endl;
    else if (n[0] && n[1]) // gu pa
        rep(i, 5) if (hand[i]) cout
        << "1" << endl;
    else cout << "2" << endl;
    else rep(i, 5) if (hand[i] == 1) cout << "1" << endl;
    else cout << "2" << endl;
  }
}
Problem p00205 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
int main(void) {
  int a[5] = {0};
  int guu = 0, tyoki = 0, paa = 0;
  int n = 1;
  int i = 0;
  while (n != 0) {
    for (i = 0; i < 5; i++) {
      scanf("%d", &a[i]);

      if (a[i] == 0) {
        break;
      } else if (a[i] == 1) {
        guu = 1;
      } else if (a[i] == 2) {
        tyoki = 1;
      } else if (a[i] == 3) {
        paa = 1;
      }
    }
    if (a[i] == 0) {
      break;
    }
    for (i = 0; i < 5; i++) {
      if (guu == 1 && tyoki == 1 && paa == 1) {
        printf("3\\n");
      } else if (guu == 1 && tyoki == 1 && paa == 0) {
        if (a[i] == 1) {
          printf("1\\n");
        } else {
          printf("2\\n");
        }
      } else if (guu == 1 && tyoki == 0 && paa == 0) {
        printf("3\\n");
      } else if (guu == 1 && tyoki == 0 && paa == 1) {
        if (a[i] == 1) {
          printf("2\\n");
        } else {
          printf("1\\n");
        }
      } else if (tyoki == 1 && paa == 1) {
        if (a[i] == 2) {
          printf("1\\n");
        } else {
          printf("2\\n");
        }
      } else if (tyoki == 1 && paa == 0) {
        printf("3\\n");
      } else if (paa == 1) {
        printf("3\\n");
      }
      a[i] = 0;
    }
    guu = 0, tyoki = 0, paa = 0;
  }
}

Error: TLE

Fixed submission:

#include <stdio.h>
int main(void) {
  int a[5] = {0};
  int guu = 0, tyoki = 0, paa = 0;
  int n = 1;
  int i = 0;
  while (n != 0) {
    for (i = 0; i < 5; i++) {
      scanf("%d", &a[i]);

      if (a[i] == 0) {
        break;
      } else if (a[i] == 1) {
        guu = 1;
      } else if (a[i] == 2) {
        tyoki = 1;
      } else if (a[i] == 3) {
        paa = 1;
      }
    }
    for (i = 0; i < 5; i++) {
      if (guu == 1 && tyoki == 1 && paa == 1) {
        printf("3\\n");
      } else if (guu == 1 && tyoki == 1 && paa == 0) {
        if (a[i] == 1) {
          printf("1\\n");
        } else {
          printf("2\\n");
        }
      } else if (guu == 1 && tyoki == 0 && paa == 0) {
        printf("3\\n");
      } else if (guu == 1 && tyoki == 0 && paa == 1) {
        if (a[i] == 1) {
          printf("2\\n");
        } else {
          printf("1\\n");
        }
      } else if (tyoki == 1 && paa == 1) {
        if (a[i] == 2) {
          printf("1\\n");
        } else {
          printf("2\\n");
        }
      } else if (tyoki == 1 && paa == 0) {
        printf("3\\n");
      } else if (paa == 1) {
        printf("3\\n");
      }
      a[i] = 0;
    }
    guu = 0, tyoki = 0, paa = 0;
  }
}
Problem p00205 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int main(void) {
  int a[5], i;
  while (scanf("%d", &a[0]), a[0] != 0) {
    int used[3];
    used[0] = used[1] = used[2] = 0;
    used[a[0] - 1] = 1;
    for (i = 1; i < 5; i++)
      scanf("%d", &a[i]), used[a[i] - 1] = 1;
    int sum = used[0] + used[1] + used[2];
    if (sum != 2) {
      for (i = 0; i < 5; i++)
        printf("3\\n");
      continue;
    }
    for (i = 0; i < 5; i++) {
      switch (a[i]) {
      case 1:
        if (used[1])
          printf("1\\n");
        else
          printf("2\\n");
        break;
      case 2:
        if (used[2])
          printf("1\\n");
        else
          printf("2\\n");
        break;
      case 3:
        if (used[0])
          printf("1\\n");
        else
          printf("2\\n");
        break;
      }
    }
  }
}

Error: TLE

Fixed submission:

#include <stdio.h>

int main(void) {
  int a[5], i;
  while (scanf("%d", &a[0])) {
    int used[3];
    used[0] = used[1] = used[2] = 0;
    for (i = 1; i < 5; i++)
      scanf("%d", &a[i]), used[a[i] - 1] = 1;
    if (used[0] && used[1] && used[2]) {
      for (i = 0; i < 5; i++)
        printf("3\\n");
      continue;
    }
    for (i = 0; i < 5; i++) {
      switch (a[i]) {
      case 1:
        if (used[1])
          printf("1\\n");
        else
          printf("2\\n");
        break;
      case 2:
        if (used[2])
          printf("1\\n");
        else
          printf("2\\n");
        break;
      case 3:
        if (used[0])
          printf("1\\n");
        else
          printf("2\\n");
        break;
      }
    }
  }
}
Problem p00205 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>

int main() {
  int h[5], c[4];

  while (scanf("%d", h) && h[0]) {
    c[0] = c[1] = c[2] = c[3] = 0;
    c[h[0]]++;
    for (int i = 1; i < 5; ++i) {
      scanf("%d", h + i);
      c[h[i]]++;
    }

    if (c[1] && c[2] && c[3])
      for (int i = 0; i < 5; ++i)
        puts("3");
    else if (c[1] && c[2])
      for (int i = 0; i < 5; ++i)
        puts(h[i] == 1 ? "1" : "2");
    else if (c[2] && c[3])
      for (int i = 0; i < 5; ++i)
        puts(h[i] == 2 ? "1" : "2");
    else if (c[3] && c[1])
      for (int i = 0; i < 5; ++i)
        puts(h[i] == 3 ? "1" : "2");
    else
      for (int i = 0; i < 5; ++i)
        puts("3");
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>

int main() {
  int h[5], c[4];

  while (scanf("%d", h) && h) {
    c[0] = c[1] = c[2] = c[3] = 0;
    c[h[0]]++;
    for (int i = 1; i < 5; ++i) {
      scanf("%d", h + i);
      c[h[i]]++;
    }

    if (c[1] && c[2] && c[3])
      for (int i = 0; i < 5; ++i)
        puts("3");
    else if (c[1] && c[2])
      for (int i = 0; i < 5; ++i)
        puts(h[i] == 1 ? "1" : "2");
    else if (c[2] && c[3])
      for (int i = 0; i < 5; ++i)
        puts(h[i] == 2 ? "1" : "2");
    else if (c[3] && c[1])
      for (int i = 0; i < 5; ++i)
        puts(h[i] == 3 ? "1" : "2");
  }
  return 0;
}
Problem p00205 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int a[5];

bool input() {
  cin >> a[0];
  if (!a[0]) {
    return false;
  }
  for (int i = 1; i < 5; ++i) {
    cin >> a[i];
  }
  return true;
}

void print_aiko() {
  for (int i = 0; i < 5; ++i) {
    cout << 3 << endl;
  }
}

void print_win_lose(int d) {
  for (int i = 0; i < 5; ++i) {
    if (a[i] == (d + 1) % 3 + 1) {
      cout << 1 << endl;
    } else {
      cout << 2 << endl;
    }
  }
}

void solve() {
  int c[3] = {0};
  for (int i = 0; i < 5; ++i) {
    ++c[a[i] - 1];
  }
  int b = 0;
  for (int i = 0; i < 3; ++i) {
    if (c[i]) {
      ++b;
    }
  }
  if (b == 1 || b == 3) {
    print_aiko();
    return;
  }
  int d = -1;
  for (int i = 0; i < 3; ++i) {
    if (!c[i]) {
      d = i;
      break;
    }
  }
  print_win_lose(d);
}

int main() {
  while (input()) {
    solve();
  }
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
#include <set>
using namespace std;

typedef set<int> S;

const int NMAX = 500;
const double EPS = 1.0e-6;
const double INF = 1.0e10;

int N;
double R;
double x[NMAX];
double y[NMAX];
double r[NMAX];
double v[NMAX];

bool input() {
  cin >> R >> N;
  if (!R && !N) {
    return false;
  }
  for (int i = 0; i < N; ++i) {
    cin >> x[i] >> y[i] >> r[i] >> v[i];
  }
  return true;
}

void solve() {
  S s;
  for (int i = 0; i < N; ++i) {
    s.insert(i);
  }

  int ans = 0;
  while (!s.empty()) {
    int t = -1;
    double td = INF;
    for (S::iterator it = s.begin(); it != s.end();) {
      int n = *it;
      double d = sqrt(x[n] * x[n] + y[n] * y[n]);
      double nd = d - v[n];
      if (nd < R - EPS) {
        s.erase(it++);
        ++ans;
        continue;
      }
      if (td > nd) {
        td = nd;
        t = n;
      }
      x[n] *= nd / d;
      y[n] *= nd / d;
      ++it;
    }
    if (t == -1) {
      break;
    }
    double zt = atan2(y[t], x[t]);
    for (S::iterator it = s.begin(); it != s.end();) {
      int n = *it;
      double d2 = x[n] * x[n] + y[n] * y[n];
      double d = sqrt(d2);
      double z1 = atan2(y[n], x[n]);
      double z2;
      if (d - r[n] < EPS - R) {
        z2 = M_PI;
      } else if (d - r[n] >= 0) {
        z2 = atan2(r[n], sqrt(d2 - r[n] * r[n]));
      } else {
        double k = (r[n] * r[n] - R * R - d * d) / (2 * d);
        z2 = atan2(k, sqrt(R * R - k * k)) + M_PI / 2;
      }
      double zu = z1 + z2;
      double zl = z1 - z2;
      bool hit;
      if (zu > M_PI) {
        hit = ((zl - EPS < zt && zt <= M_PI) ||
               (-M_PI <= zt && zt < zu + EPS - 2 * M_PI));
      } else if (zl < -M_PI) {
        hit = ((zl + 2 * M_PI - EPS < zt && zt <= M_PI) ||
               (-M_PI <= zt && zt < zu + EPS));
      } else {
        hit = (zl - EPS < zt && zt < zu + EPS);
      }
      if (hit) {
        s.erase(it++);
      } else {
        ++it;
      }
    }
  }
  cout << ans << endl;
}

int main() {
  while (input()) {
    solve();
  }
}
Problem p00206 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
int main(void) {
  int w, n, z, x, i, k, c;
  while (1) {
    scanf("%d", &n);
    if (n == 0)
      break;
    c = 0;
    k = 0;
    for (i = 0; i < 12; i++) {
      scanf("%d %d", &z, &x);
      k += z - x;
      if (k >= n) {
        c++;
      }
    }
    if (k < n) {
      printf("NA\\n");
    } else {
      printf("%d\\n", 12 - c + 1);
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
int main(void) {
  int w, n, z, x, i, k, c;
  while (1) {
    c = 0;
    k = 0;
    scanf("%d", &n);
    if (n == 0)
      break;
    for (i = 0; i < 12; i++) {
      scanf("%d %d", &z, &x);
      k += z - x;
      c++;
      if (k > n) {
        i = 10000;
      }
    }
    if (c == 0 || c >= 12) {
      printf("NA\\n");
    } else {
      printf("%d\\n", c);
    }
  }
  return 0;
}
Problem p00206 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int a, ans, moku, b, tyokin;
  while (1) {
    cin >> moku;
    if (moku == 0) {
      goto a;
    }
    tyokin = 0;
    ans = 0;
    for (int i = 1; i <= 12; i++) {
      cin >> a >> b;
      tyokin += a - b;
      if (moku <= tyokin) {
        ans = i;
        tyokin = -99999999;
      }
    }
    if (ans == 0) {
      cout << "NA" << endl;
    } else {
      cout << ans << endl;
    }
  }
a:;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int a, ans, moku, b, tyokin;
  while (1) {
    cin >> moku;
    tyokin = 0;
    ans = 0;
    for (int i = 1; i <= 12; i++) {
      cin >> a >> b;
      tyokin += a - b;
      if (moku <= tyokin) {
        ans = i;
        tyokin = -99999999;
      }
    }
    if (ans == 0) {
      cout << "NA" << endl;
    } else {
      cout << ans << endl;
    }
  }
}
Problem p00206 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define vi vector<int>
#define vvi vector<vector<int>>
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
using namespace std;
typedef pair<int, int> pii;
#define MAX 99999999
int main() {
  int n;
  while (cin >> n && n) {
    int sum = 0;
    int hoge = INF;
    bool s = true;
    rep(i, 12) {
      pii p;
      cin >> p.first >> p.second;
      sum += p.first - p.second;
      if (sum >= n && s) {
        hoge = i + 1;
        s = false;
      }
    }
    if (hoge == INF) {
      cout << "NA" << endl;
    } else
      cout << hoge << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define vi vector<int>
#define vvi vector<vector<int>>
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
using namespace std;
typedef pair<int, int> pii;
#define MAX 99999999
int main() {
  int l;
  while (cin >> l, l) {
    vi v(12, 0);
    vi u(12, 0);
    int sum = 0;
    int hoge = INF;
    rep(i, 12) {
      cin >> v[i] >> u[i];
      sum += (v[i] - u[i]);
      if (sum > l) {
        hoge = i + 1;
        break;
      }
    }
    (hoge != INF ? cout << hoge << endl : cout << "NA" << endl);
  }
}
Problem p00206 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int main(void) {
  int L, M, N, k[12], i, kai;

  while (0 == 0) {
    scanf("%d", &L);
    if (L == 0)
      break;
    kai = 0;
    for (i = 1; i < 13; i++) {
      scanf("%d %d\\n", &M, &N);
      k[i] = M - N;
    }
    for (i = 1; i < 13; i++) {
      L -= k[i];
      if (L <= 0) {
        kai = i;
        break;
      }
    }
    if (kai == 0)
      printf("NA\\n");
    else
      printf("%d\\n", kai);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

int main(void) {
  int L, M, N, k[12], i, kai;

  while (scanf("%d\\n", &L) != 0) {

    kai = 0;

    for (i = 1; i < 13; i++) {
      scanf("%d %d\\n", &M, &N);
      k[i] = M - N;
    }

    for (i = 1; i < 1; i++) {
      L -= k[i];
      if (L <= 0) {
        kai = i;
        break;
      }
    }

    if (kai == 0)
      printf("NA\\n");
    else
      printf("%d\\n", kai);
  }
  return 0;
}