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

#include <iostream>
using namespace std;
int main() {
  int n;
  int m;
  int c;
  int d;
  while (cin >> n) {
    cin >> m;
    if (n == 0) {
      break;
    }
    int a[n];
    int b[m];
    c = 0;
    while (c < n) {
      cin >> a[c];
      c = c + 1;
    }
    c = 0;
    while (c < m) {
      cin >> b[c];
      c = c + 1;
    }
    d = 0;
    c = 0;
    while (c < m) {
      d = d + b[c];
      if (d >= n - 1) {
        break;
      }
      d = d + a[d];
      if (d >= n - 1) {
        break;
      }
      c = c + 1;
    }
    cout << c + 1 << endl;
  }
}

Error: -11

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int main() {
  int n;
  while (cin >> n) {
    int m;
    cin >> m;
    if (n == 0) {
      break;
    }
    int a[n];
    int b[m];
    int c;
    c = 0;
    while (c < n) {
      cin >> a[c];
      c = c + 1;
    }
    c = 0;
    while (c < m) {
      cin >> b[m];
      c = c + 1;
    }
    int d;
    d = 0;
    c = 0;
    while (c < m) {
      d = d + b[c];
      d = d + a[d];
      c = c + 1;
      if (d > n - 2) {
        break;
      }
    }
    cout << c << endl;
  }
}
Problem p00467 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
int S[1000];
int main() {
  int N, M;
  while (scanf("%d %d", &N, &M), N | M) {
    for (int i = 0; i < N; i++)
      scanf("%d", &S[i]);
    int x = 0;
    int ans = 1 << 30;
    for (int i = 0; i < M; i++) {
      int y;
      scanf("%d", &y);
      if (x >= (N - 1))
        continue;
      x += y;
      if ((N - 1) >= x)
        x += S[x];
      if (x >= (N - 1))
        ans = i + 1;
    }
    printf("%d\\n", ans);
  }
}

Error: 0

Fixed submission:

#include <cstdio>
int S[1000];
int main() {
  int N, M;
  while (scanf("%d %d", &N, &M), N | M) {
    for (int i = 0; i < N; i++)
      scanf("%d", &S[i]);
    int x = 0;
    int ans = 1 << 30;
    for (int i = 0; i < M; i++) {
      int y;
      scanf("%d", &y);
      x += y;
      x += S[x];
      if (x >= N - 1 && ans > (i + 1))
        ans = (i + 1);
    }
    printf("%d\\n", ans);
  }
}
Problem p00467 (C++) — buggy submission, verdict: Runtime Error


#include <iostream>
using namespace std;

int main() {
  int eye[10000], N, M, masu[10000], B, i, ima, L, C, D, j, n = 0, c = 0,
                                                            ba = 0;
  cin >> N >> M;
  while (N != 0 || M != 0) {
    for (i = 1; i <= N; i++) {
      cin >> masu[i];
    }
    ima = 1;
    for (i = 0; i < M; i++) {
      cin >> eye[i];
    }
    for (i = 1; i <= M; i++) {
      ima = ima + eye[i - 1];
      if (ima >= N) {
        n = i;
        break;
      }
      ima = ima + masu[ima];
      if (ima >= N) {
        n = i;
        break;
      }
    }
    cout << n << endl;
    cin >> N >> M;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int eye[100], N, M, masu[100], B, i, ima, L, C, D, j, n = 0, c = 0, ba = 0;
  cin >> N >> M;
  while (N != 0 || M != 0) {
    for (i = 1; i <= N; i++) {
      cin >> masu[i];
    }
    ima = 1;
    for (i = 0; i < M; i++) {
      cin >> eye[i];
    }
    for (i = 1; i <= M; i++) {
      ima = ima + eye[i - 1];
      if (ima >= N) {
        n = i;
        break;
      }
      ima = ima + masu[ima];
      if (ima >= N) {
        n = i;
        break;
      }
    }
    cin >> N >> M;
  }
  cout << n << endl;
  return 0;
}
Problem p00467 (C++) — buggy submission, verdict: Runtime Error

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

Error: 0

Fixed submission:

#include <stdio.h>
int main(void) {
  int a, b, x[101], s[101], cnt = 0, X = 0, i;
  while (1) {
    scanf("%d%d", &a, &b);
    if (a == 0 && b == 0)
      break;
    for (i = 0; i < a; i++) {
      scanf("%d", &x[i]);
    }
    for (i = 0; i < b; i++) {
      scanf("%d", &s[i]);
    }
    for (i = 0; i < b; i++) {
      X += s[i];
      X += x[X];
      cnt++;
      if (X >= a)
        break;
    }
    printf("%d\\n", cnt);
  }
  return 0;
}
Problem p00467 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long

using namespace std;
int main() {
  int n, m;
  while (cin >> n >> m, n + m) {
    int sugoroku[n + 1000];
    fill_n(sugoroku, n + 1000, 0);
    for (int i = 0; i < n; i++)
      cin >> sugoroku[i];
    int now = 1;
    int ans = -1;
    int flag = true;
    for (int i = 0; i < m; i++) {
      int me;
      cin >> me;
      if (flag)
        now = now + me + sugoroku[now + me - 1];
      // cout<<now<<endl;
      if (now < 0)
        now = 0;
      if (now >= n && flag) {
        ans = i + 1;
        flag = false;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long

using namespace std;
int main() {
  int n, m;
  while (cin >> n >> m, n + m) {
    int sugoroku[n + 1000];
    fill_n(sugoroku, n + 1000, 0);
    for (int i = 0; i < n; i++)
      cin >> sugoroku[i];
    int now = 1;
    int ans = -1;
    int flag = true;
    for (int i = 0; i < m; i++) {
      int me;
      cin >> me;
      now = now + me + sugoroku[now + me - 1];
      // cout<<now<<endl;
      if (now < 0)
        now = 0;
      if (now >= n && flag) {
        ans = i + 1;
        flag = false;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00467 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main() {
  while (true) {
    int N, M;
    scanf("%d%d", &N, &M);
    if (N == 0 && M == 0)
      return 0;
    int C[1000];
    for (int i = 0; i < N; i++)
      scanf("%d", &C[i]);
    int B = 0;
    int S[1000];
    for (int i = 0; i < M; i++)
      scanf("%d", &S[i]);
    for (int i = 0; i < M; i++) {
      B += S[i];
      if (B >= N - 1) {
        printf("%d\\n", i + 1);
        break;
      }
      B += C[B];
      if (B >= N - 1) {
        printf("%d\\n", i + 1);
        break;
      }
    }
  }
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int n, m, a[1001];
  while (true) {
    scanf("%d%d", &n, &m);
    if (n == 0 && m == 0)
      return 0;
    for (int i = 1; i <= n; i++)
      scanf("%d", &a[i]);
    int x = 1;
    int y;
    for (int i = 1; i <= m; i++) {
      scanf("%d", &y);
      x += y;
      x += a[x];
      if (x == n) {
        printf("%d\\n", i);
        break;
      }
    }
  }
}
Problem p00467 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int n, m;
  while (1) {
    cin >> n >> m;
    if (n == 0 || m == 0) {
      break;
    }
    int dat[1100], cnt = 0, x, ans = 0;
    for (int i = 0; i < n; i++) {
      cin >> dat[i];
    }
    for (int i = 0; i < m; i++) {
      cin >> x;
      cnt += x;
      ans++;
      if (cnt >= n) {
        for (int j = i + 1; j < m; j++) {
          cin >> x;
        }
        break;
      }
      cnt += dat[cnt];
      if (cnt >= n) {
        for (int j = i + 1; j < m; j++) {
          cin >> x;
        }

        break;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, m;
  while (1) {
    cin >> n >> m;
    if (n == 0 && m == 0) {
      break;
    }
    int dat[1100], cnt = 0, x, ans = 0;
    for (int i = 0; i < n; i++) {
      cin >> dat[i];
    }
    for (int i = 0; i < m; i++) {
      cin >> x;
      cnt += x;
      ans++;
      if (cnt >= n) {
        break;
      }
      cnt += dat[cnt];
      if (cnt >= n) {
        break;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00467 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define fo(i, a) for (i = 0; i < a; i++)
using namespace std;
int main(void) {
  int n, m, d, i, cnt = 0, now = 0, flag = 0, x[3001] = {0};

  cin >> n >> m;
  while (n != 0 && m != 0) {
    fo(i, n) cin >> x[i];
    i = 0;
    fo(i, m) {
      cin >> d;
      now += d + x[now + d];

      now = now > 1000 ? 1000 : now;

      if (flag == 0)
        cnt++;
      if (now >= n)
        flag = 1;
    }
    cout << cnt << endl;
    cnt = 0;
    now = 0;
    flag = 0;
    cin >> n >> m;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define fo(i, a) for (i = 0; i < a; i++)
using namespace std;
int main(void) {
  int n, m, d, i, cnt = 0, now = 0, flag = 0, x[3001] = {0};

  cin >> n >> m;
  while (n != 0 && m != 0) {
    fo(i, n) cin >> x[i];
    i = 0;
    fo(i, m) {
      cin >> d;
      now += d + x[now + d];
      if (flag == 0)
        cnt++;
      if (now >= n)
        flag = 1;
    }
    cout << cnt << endl;
    cnt = 0;
    now = 0;
    flag = 0;
    cin >> n >> m;
  }

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

#include <iostream>
#include <vector>

using namespace std;

int main() {
  while (true) {
    int N, M;
    cin >> N >> M;
    if (!N && !M)
      break;

    vector<int> v(N);
    int pos = 0;
    for (int i = 0; i < N; ++i) {
      cin >> v[i];
    }
    vector<int> m(M);
    for (int i = 0; i < M; ++i) {
      cin >> m[i];
    }
    for (int i = 0; i < M; ++i) {
      pos += m[i];
      if (pos >= N - 1) {
        cout << (i + 1) << endl;
        break;
      }
      pos += v[pos];
      if (pos >= N - 1) {
        cout << (i + 1) << endl;
        break;
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int main() {
  while (true) {
    int N, M;
    cin >> N >> M;
    if (!N && !M)
      break;

    vector<int> v(N);
    int pos = 0;
    for (int i = 0; i < N; ++i) {
      cin >> v[i];
    }
    for (int i = 0; i < M; ++i) {
      int m;
      cin >> m;
      pos += m;
      if (pos >= N) {
        cout << (i + 1) << endl;
        break;
      }
      pos += v[pos];
      if (pos >= N) {
        cout << (i + 1) << endl;
        break;
      }
    }
  }
  return 0;
}
Problem p00467 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main(void) {
  for (;;) {
    int N, M, a[1000] = {0}, b, c, d, e = 0, j;
    cin >> N >> M;
    if (N == 0 && M == 0)
      break;
    for (b = 0; b < N; b++) {
      cin >> a[b];
    }
    d = 0;
    for (b = 0; b < M; b++) {
      cin >> c;
      d = d + c;
      d = d + a[d];
      e++;
      if (d >= N - 1) {
        for (j = b + 1; j < M; j++) {
          cin >> c;
        }
        break;
      }
    }
    cout << e << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main(void) {
  for (;;) {
    int N, M, a[1000] = {0}, b, c, d, e = 0, j;
    cin >> N >> M;
    if (N == 0 && M == 0)
      break;
    for (b = 0; b < N; b++) {
      cin >> a[b];
    }
    d = 0;
    for (b = 0; b < M; b++) {
      cin >> c;
      d = d + c;
      d = d + a[d];
      e++;
      if (d >= N - 1) {
        for (j = b + 1; j < M; j++) {
          cin >> c;
        }
      }
      break;
    }
    cout << e << endl;
  }
  return 0;
}
Problem p00467 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, m;

  while (cin >> n >> m && n != 0 && m != 0) {
    int date[1024];
    memset(date, 0, sizeof(date));
    for (int i = 0; i < n; ++i) {
      cin >> date[i];
    }
    int me;
    int point = 0;
    int ans;
    bool flg = true;
    for (int i = 0; i < m; ++i) {
      cin >> me;
      if (flg) {
        point += me;
        point += date[point];
        if (point >= n - 1) {
          ans = i + 1;
          flg = false;
        }
      }
    }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

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

int main() {
  int n, m;
  cin >> n >> m;
  while (n != 0 && m != 0) {
    int date[1024];
    memset(date, 0, sizeof(date));
    for (int i = 0; i < n; ++i) {
      cin >> date[i];
    }
    int me;
    int point = 0;
    int ans;
    bool flg = true;
    for (int i = 0; i < m; ++i) {
      cin >> me;
      if (flg) {
        point += me;
        point += date[point];
        if (point >= n - 1) {
          ans = i + 1;
          flg = false;
        }
      }
    }
    cout << ans << endl;
  }
}
Problem p00467 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int main() {
  int s[9000], n, m, t, f, i;
  while (scanf("%d%d", &n, &m), n)
    for (i = t = f = 1; i <= n + m; i++) {
      scanf("%d", &s[i]);
      if (i > n)
        if (t += s[t += s[i]], t >= n & f == 1)
          printf("%d\\n", i - n, f = 0);
    }
}

Error: -11

Fixed submission:

#include <stdio.h>
int main() {
  int s[9000], n, m, t, f, i;
  while (scanf("%d%d", &n, &m), n)
    for (i = t = f = 1; i <= n + m | scanf("%d", &s[i]); i++) {
      ;
      if (i > n)
        if (t += s[t += s[i]], t >= n & f == 1)
          printf("%d\\n", i - n, f = 0);
    }
}
Problem p00467 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int main() {
  while (1) {
    int N, M;
    cin >> N >> M;
    if (!N && !M)
      break;

    int v[N];
    int pos = 0;
    for (int i = 0; i < N; ++i) {
      cin >> v[i];
    }
    int m[M];
    for (int i = 0; i < M; ++i) {
      cin >> m[i];
    }
    for (int i = 0; i < M; ++i) {
      pos += m[i];
      if (pos >= N - 1) {
        cout << (i + 1) << endl;
        break;
      }
      pos += v[pos];
      if (pos >= N - 1) {
        cout << (i + 1) << endl;
        break;
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, m, i, cnt, num;
  while (1) {
    cnt = 0;
    cin >> n >> m;
    if (n == 0)
      break;
    int s[n];
    for (i = 0; i < n; i++)
      cin >> s[i];
    for (i = 0; i < m; i++) {
      cin >> num;
      cnt += num;
      if (cnt < 0)
        cnt = 0;
      cnt += s[cnt];
      if (cnt < 0)
        cnt = 0;
      if (cnt >= n - 1)
        break;
    }
    cout << i + 1 << endl;
  }
  return 0;
}
Problem p00467 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int main() {
  int s[9000], n, m, t, f, i;
  while (scanf("%d%d", &n, &m), n)
    for (i = t = f = 1; i <= n + m; i++) {
      scanf("%d", &s[i]);
      if (i > n) {
        t += s[t += s[i]];
        if (t >= n & f == 1) {
          printf("%d\\n", i - n, f = 0);
          ;
        }
      }
    }
}

Error: -11

Fixed submission:

#include <stdio.h>
int main() {
  int s[9000], n, m, t, f, i;
  while (scanf("%d%d", &n, &m), n)
    for (i = t = f = 1; i <= n + m, scanf("%d", &s[i]); i++) {
      ;
      if (i > n) {
        t += s[t += s[i]];
        if (t >= n & f == 1) {
          printf("%d\\n", i - n);
          f = 0;
        }
      }
    }
}
Problem p00467 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int n, m, t;
  while (cin >> n >> m && n || m) {
    int now = 0, ret = -1;
    int data[1006] = {0};
    for (int i = 0; i < n; i++) {
      cin >> data[i];
    }

    for (int i = 0; i < m; i++) {
      cin >> t;
      if (ret == -1) {
        now += t;
        now += data[now];
        if (now >= n - 1) {
          ret = i;
        }
      }
    }
    cout << ret + 1 << endl;
  }
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, m, t;
  while (cin >> n >> m && n || m) {
    int now = 0, ret = -1;
    int data[3000] = {0};
    for (int i = 0; i < n; i++) {
      cin >> data[i];
    }

    for (int i = 0; i < m; i++) {
      cin >> t;
      now += t;
      now += data[now];
      if (now >= n - 1 && ret == -1) {
        ret = i;
      }
    }
    cout << ret + 1 << endl;
  }
}
Problem p00467 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) range(i, 0, b)
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main() {
  int n, m;
  while (cin >> n >> m, n || m) {
    int ans = -1, x = 0, face[1005];
    rep(i, n) cin >> face[i];
    rep(j, m) {
      int inp;
      cin >> inp;
      x += inp;
      x = min(x, n - 1);
      x += face[x];
      if (x >= n - 1 && ans == -1) {
        ans = j + 1;
      }
    }
    cout << ans << endl;
  }
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) range(i, 0, b)
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main() {
  int n, m;
  while (cin >> n >> m, n || m) {
    int ans = -1, x = 0, face[1005];
    rep(i, n) cin >> face[i];
    rep(j, m) {
      int inp;
      cin >> inp;
      x += inp;
      x += face[x];
      if (x >= n - 1 && ans == -1) {
        ans = j + 1;
      }
    }
    cout << ans << endl;
  }
}
Problem p00467 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  while (1) {
    int n, m, loc = 1, in, b[1002], ans;
    scanf("%d%d", &n, &m);
    if (n == 0 && m == 0)
      break;
    for (int i = 1; i <= n; i++)
      scanf("%d", &b[i]);
    for (int i = 1; i <= m; i++) {
      scanf("%d", &in);
      loc += in;
      if (loc >= n) {
        ans = i;
        break;
      }
      loc += b[loc];
      if (loc >= n) {
        ans = i;
        break;
      }
    }
    for (int i = ans + 1; i <= m; i++)
      scanf("%d", &in);
    printf("%d\\n", ans);
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  while (1) {
    int n, m, loc = 1, in, b[1002];
    scanf("%d%d", &n, &m);
    if (n == 0 && m == 0)
      break;
    for (int i = 1; i <= n; i++)
      scanf("%d", &b[i]);
    for (int i = 1; i <= m; i++) {
      scanf("%d", &in);
      loc += in;
      if (loc >= n) {
        printf("%d\\n", i);
        break;
      }
      loc += b[loc];
      if (loc >= n) {
        printf("%d\\n", i);
        break;
      }
    }
  }
}
Problem p00467 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  while (true) {
    int m = 0, n = 0, move[1000] = {}, turn = 0, flag = 0;
    double masu[1000] = {};
    cin >> m >> n;
    if (n == 0 || m == 0)
      break;
    for (int i = 0; i < m; i++) {
      cin >> masu[i];
    }
    for (int i = 0; i < n; i++) {
      cin >> move[i];
    }
    for (int i = 0; i < n; i++) {
      flag = flag + move[i];
      flag = flag + masu[flag];
      turn++;
      if (flag >= m)
        break;
    }
    cout << turn << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  while (true) {
    int m = 0, n = 0, move[1000] = {}, turn = 0, flag = 0;
    double masu[1000] = {};
    cin >> m >> n;
    if (n == 0 || m == 0)
      break;
    for (int i = 0; i < m; i++) {
      cin >> masu[i];
    }
    for (int i = 0; i < n; i++) {
      cin >> move[i];
    }
    for (int i = 0; i < n; i++) {
      flag = flag + move[i];
      flag = flag + masu[flag];
      turn++;
      if (flag == m)
        break;
    }
    cout << turn << endl;
  }
  return 0;
}
Problem p00467 (C++) — buggy submission, verdict: Runtime Error

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

int main() {

  for (int D = 0; D < 5; D++) {

    int n, m;
    cin >> n >> m;

    if (n == 0 && m == 0) {
      break;
    } else {

      int st[1001];
      for (int i = 1; i <= n; i++) {
        int ope;
        cin >> ope;
        st[i] = ope;
      }

      int dis[1001];
      for (int i = 1; i <= m; i++) {
        int dl;
        cin >> dl;
        dis[i] = dl;
      }

      int now = 1, i;

      for (i = 1; i <= m; i++) {

        now += dis[i];
        if (now >= n) {
          break;
        }

        now += st[now];

        if (now >= n) {
          break;
        }
      }

      cout << i << endl;
    }
  }

  return 0;
}


Error: TLE

Fixed submission:

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

  while (true) {

    int n, m;
    cin >> n >> m;

    if (n == 0 && m == 0) {
      break;
      return 0;
    }

    int N[1500];
    for (int i = 0; i < n; i++) {
      cin >> N[i];
    }

    int t = 1, x = 0;
    for (int i = 0; i < m; i++) {
      int M;
      cin >> M;

      x += M;
      if (x >= n - 1) {
        cout << t << endl;
        break;
      }

      x += N[x];
      if (x >= n - 1) {
        cout << t << endl;
        break;
      }

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

#include <cstdio>
#include <iostream>

using namespace std;
int main() {
  int masu[9000], n, m, iti, f;
  while (cin >> n >> m) {
    if (n == 0) {
      break;
    }
    iti = f = 1;
    for (int i = 1; i <= n + m; i++) {
      cin >> masu[i];
      if (i > n) {
        iti += masu[i];
        iti += masu[iti];
        if (iti >= n && f == 1) {
          printf("%d\\n", i - n);
          f = 0;
        }
      }
    }
  }
}

Error: 0

Fixed submission:

#include <cstdio>
#include <iostream>

using namespace std;
int main() {
  int masu[4000], n, m, iti, f;
  while (cin >> n >> m) {
    if (n == 0) {
      break;
    }
    iti = f = 1;
    for (int i = 1; i <= n + m; i++) {
      cin >> masu[i];
      if (i > n) {
        iti += masu[i];
        iti += masu[iti];
        if (iti >= n && f == 1) {
          printf("%d\\n", i - n);
          f = 0;
        }
      }
    }
  }
}
Problem p00467 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
using namespace std;

#define loop(i, a, b) for (int i = (a); i < int(b); i++)
#define rep(i, b) loop(i, 0, b)
#define all(c) (c).begin(), (c).end()

int a[10000];

int main() {
  int n, m;
  while (cin >> n >> m && n) {
    rep(i, n) cin >> a[i + 1];
    int p = 1;
    int ans = 0;
    rep(i, m) {
      int k;
      cin >> k;
      p += k + a[p + k];
      if (!ans && p >= n)
        ans = i + 1;
    }
    cout << ans << endl;
  }
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
using namespace std;

#define loop(i, a, b) for (int i = (a); i < int(b); i++)
#define rep(i, b) loop(i, 0, b)
#define all(c) (c).begin(), (c).end()

int main() {
  int n, m;
  int a[1000];
  while (cin >> n >> m && n) {
    rep(i, n) cin >> a[i + 1];
    int p = 1;
    int ans = 0;
    rep(i, m) {
      int k;
      cin >> k;
      p += k + a[p + k];
      if (!ans && p >= n)
        ans = i + 1;
    }
    cout << ans << endl;
  }
}