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

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#pragma warning(disable : 4786) // VisualC++6.0の警告対策

using namespace std;

#define ll long long
#define SINT(n) scanf("%d", &n);
#define SLL(n) scanf("%lld", &n);

#define PINT(n) printf("%d", (int)(n));
#define PLL(n) printf("%lld", (long long)(n));
#define PINTN(n) printf("%d\\n", (int)(n));
#define PLLN(n) printf("%lld\\n", (long long)(n));
#define PSP() printf(" ");
#define PN() printf("\\n");

#define dlp(i) while (i-- > 0)
#define ulp(i)                                                                 \\
  for (int _hoge_counter_hoge_ = i, i = 0; i < _hoge_counter_hoge_; i++)
#define lp(i, to) for (i = 0; i < to; i++)
#define lpp(i, from, to) for (i = from; i < to; i++)

map<ll, map<ll, short>> memo[50][50][4];

char Map[60][60];

int main() {

  int N, M;
  int i, j, k;
  int a;
  int now;
  int masu[1050];
  int me[1050];

  while (1) {
    SINT(N);
    SINT(M);
    if (N == 0 && M == 0)
      break;
    lp(i, N) SINT(masu[i]);
    lp(i, M) SINT(me[i]);

    now = 0;
    lp(i, M) {
      a = me[i];
      now += a;
      if (now >= N - 1)
        break;
      now += masu[now];
      if (now >= N - 1)
        break;
    }
    PINTN(i + 1);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#pragma warning(disable : 4786) // VisualC++6.0の警告対策

using namespace std;

#define ll long long
#define SINT(n) scanf("%d", &n);
#define SLL(n) scanf("%lld", &n);

#define PINT(n) printf("%d", (int)(n));
#define PLL(n) printf("%lld", (long long)(n));
#define PINTN(n) printf("%d\\n", (int)(n));
#define PLLN(n) printf("%lld\\n", (long long)(n));
#define PSP() printf(" ");
#define PN() printf("\\n");

#define dlp(i) while (i-- > 0)
#define ulp(i)                                                                 \\
  for (int _hoge_counter_hoge_ = i, i = 0; i < _hoge_counter_hoge_; i++)
#define lp(i, to) for (i = 0; i < to; i++)
#define lpp(i, from, to) for (i = from; i < to; i++)

map<ll, map<ll, short>> memo[50][50][4];

char Map[60][60];

int main() {

  int N, M;
  int i, j, k;
  int a;
  int now;
  int masu[1050];

  while (1) {
    SINT(N);
    SINT(M);
    if (N == 0 && M == 0)
      break;
    lp(i, N) SINT(masu[i]);

    now = 0;
    lp(i, M) {
      SINT(a);
      now += a;
      if (now >= N - 1)
        break;
      now += masu[now];
      if (now >= N - 1)
        break;
    }
    PINTN(i + 1);
  }

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

#include <bits/stdc++.h>
#define LL long long
using namespace std;
static const LL INF = 1LL << 60LL;
typedef pair<int, int> pii;

int n, m;
int C[2016], D[2016];
int res;
int place = 1;

int main() {
  while (1) {
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    memset(C, 0, sizeof(C));
    memset(D, 0, sizeof(D));
    for (int i = 1; i <= n; ++i) {
      cin >> C[i];
    }
    for (int i = 1; i <= m; ++i) {
      cin >> D[i];
    }
    for (int i = 1; i <= m; ++i) {
      place += D[i];
      place += C[place];
      res++;
      if (place >= n)
        break;
    }
    cout << res << endl;
    res = 0;
    place = 1;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define LL long long
using namespace std;
static const LL INF = 1LL << 60LL;
typedef pair<int, int> pii;

int n, m;
int C[2016];
int res;
int place = 1;

int main() {
  while (1) {
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    memset(C, 0, sizeof(C));
    for (int i = 1; i <= n; ++i) {
      cin >> C[i];
    }
    for (int i = 1; i <= m; ++i) {
      int x;
      cin >> x;
      place += x;
      place += C[place];
      res++;
      if (place >= n)
        break;
    }
    cout << res << endl;
    res = 0;
  }
}
Problem p00467 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int n, m, c, g, a[10000];
int main() {
  while (true) {
    cin >> n >> m;
    c = 1;
    g = 0;
    if (n == 0 && m == 0)
      break;
    for (int i = 1; i <= n; i++)
      cin >> a[i];
    for (int i = 1; i <= m; i++) {
      int p;
      cin >> p;
      c += p;
      c += a[c];
      if (c >= n && g == 0) {
        g = i;
      }
    }
    cout << g << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int n, m, c, g, a[10000];
int main() {
  while (true) {
    cin >> n >> m;
    c = 1;
    g = 0;
    for (int i = 1; i <= n; i++)
      cin >> a[i];
    for (int i = 1; i <= m; i++) {
      int p;
      cin >> p;
      c += p;
      c += a[c];
      if (c >= n && g == 0) {
        g = i;
      }
    }
    cout << g << endl;
  }
  return 0;
}
Problem p00467 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
int main() {
  int N, M;
  while (1) {
    int n[4000] = {};
    int G = 0;
    int H = 0;
    cin >> N >> M;
    if (N == 0 && M == 0)
      break;
    for (int i = 0; i < N; i++) {

      cin >> n[i];
    }
    bool f = false;
    for (int i = 0; i < M; i++) {
      int x;
      cin >> x;
      G += x;
      G += n[G];
      if (G >= N - 1 && f == false) {
        f = true;
        H = i + 1;
      }
      // cout<<"#"<<i<<G<<endl;
    }
    cout << H << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
int main() {
  int N, M;
  while (1) {
    int n[4000] = {};
    int G = 0;
    int H = 0;
    cin >> N >> M;
    if (N == 0 && M == 0)
      break;
    for (int i = 0; i < N; i++) {

      cin >> n[i];
    }

    for (int i = 0; i < M; i++) {
      int x;
      cin >> x;
      G += x;
      G += n[G];
      if (G >= N - 1) {
        H = i + 1;
        break;
      }
      // cout<<"#"<<i<<G<<endl;
    }
    cout << H << endl;
  }
  return 0;
}
Problem p00467 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>

using namespace std;

int main() {
  int n, m;
  int x[1000];
  int s[1000];
  int masu = 0;
  while (true) {
    masu = 0;
    cin >> n >> m;
    if (n == 0 && m == 0) {
      break;
    }
    for (int i = 0; i < n; i++) {
      cin >> x[i];
    }
    for (int i = 0; i < m; i++) {
      cin >> s[i];
    }
    int i = 0;
    while (true) {
      masu += s[i];
      if (masu >= n - 1) {
        cout << i + 1 << endl;
        break;
      }
      masu += x[masu];
      if (masu >= n) {
        cout << i + 1 << endl;
        break;
      }
      i++;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

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

#include <stdio.h>
int main() {
  int n, m, l[10000], i, x, p, a;
  while (1) {
    scanf("%d%d", &n, &m);
    p = 0;
    a = 0;
    if (n == 0 && m == 0) {
      break;
    }

    for (i = 0; i < 1024; i++) {
      l[i] = 0;
    }

    for (i = 0; i < n; i++) {
      scanf("%d", &l[i]);
    }
    for (i = 0; i < m; i++) {
      scanf("%d", &x);
      p += x + l[p + x];
      if (p >= n - 1 && a == 0) {
        a = i + 1;
      }
    }
    printf("%d\\n", a);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>
int main() {
  int n, m, l[1024] = {0}, i, x, p, a;
  while (1) {
    scanf("%d%d", &n, &m);
    p = 0;
    a = 0;
    if (n == 0 && m == 0) {
      break;
    }

    for (i = 0; i < 1024; i++) {
      l[i] = 0;
    }

    for (i = 0; i < n; i++) {
      scanf("%d", &l[i]);
    }
    for (i = 0; i < m; i++) {
      scanf("%d", &x);
      p += x + l[p + x];
      if (p >= n - 1 && a == 0) {
        a = i + 1;
      }
    }
    printf("%d\\n", a);
  }
  return 0;
}
Problem p00467 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
#define MAX 1000

int main() {
  int n, m;
  int ms[MAX + 1];

  while (true) {
    cin >> n >> m;
    if (!n && !m)
      break;

    for (int i = 0; i < n; i++)
      cin >> ms[i];

    int go, t = 0, cnt = 0;
    bool flg = false;

    for (int i = 0; i < m; i++) {
      cin >> go;
      if (!flg) {
        t += go;
        t += ms[t];
        cnt++;
        if (t >= n - 1)
          flg = true;
      }
    }
    cout << cnt << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
#define MAX 1000

int main() {
  int n, m;
  int ms[MAX + 1];

  while (true) {
    cin >> n >> m;
    if (!n && !m)
      break;

    for (int i = 0; i < n; i++)
      cin >> ms[i];

    int go, t = 0, cnt = 0;
    for (int i = 0; i < m; i++) {
      cin >> go;
      t += go;
      t += ms[t];
      cnt++;
      if (t >= 9)
        break;
    }
    cout << cnt << endl;
  }

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

#include <cstring>
#include <iostream>
using namespace std;
int main() {
  int ban, val, pos = 0, tmp, i, sd = 0;
  int borad[1000], masu[1000] = {0};

  while (cin >> ban >> val) {
    pos = 0;
    if (ban == 0 && val == 0)
      break;
    memset(masu, 0, sizeof(masu));
    memset(borad, 0, sizeof(borad));
    for (i = 0; i < ban; i++)
      cin >> borad[i];
    for (i = 0; i < val; i++)
      cin >> masu[i];
    for (i = 0; i < val; i++) {
      if (pos >= ban)
        break;
      pos += masu[i];
      pos += borad[pos];
    }

    cout << i << endl;
  }
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int ban, val, pos = 0, tmp, i, sd;
  int borad[1000] = {0};
  while (cin >> ban >> val) {
    if (ban == 0 && val == 0)
      break;
    for (i = 0; i < ban; i++)
      cin >> borad[i];
    for (i = 0; i < val; i++) {
      cin >> tmp;
      pos += tmp;
      if (pos >= ban) {
        sd = i;
      }
      pos += borad[pos];
    }
    cout << sd << endl;
  }
}
Problem p00467 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
#define MAX 2000

int main() {
  int n, m;
  int ms[MAX + 1];

  while (true) {
    cin >> n >> m;
    if (!n && !m)
      break;

    for (int i = 0; i < n; i++)
      cin >> ms[i];

    int go, t = 0, cnt = 0;
    bool flg = false;

    for (int i = 0; i < m; i++) {
      cin >> go;
      if (!flg) {
        t += go;
        t += ms[t];
        cnt++;
        if (t >= n - 1)
          flg = true;
      }
    }
    cout << cnt << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
#define MAX 1000

int main() {
  int n, m;
  int ms[MAX + 1];

  while (true) {
    cin >> n >> m;
    if (!n && !m)
      break;

    for (int i = 0; i < n; i++)
      cin >> ms[i];

    int go, t = 0, cnt = 0;
    bool flg = false;

    for (int i = 0; i < m; i++) {
      cin >> go;
      if (!flg) {
        t += go;
        t += ms[t];
        cnt++;
        if (t >= n - 1)
          flg = true;
      }
    }
    cout << cnt << endl;
  }

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

#include <iostream>

using namespace std;

int main() {
  int n, m;
  int map[3000] = {0};
  int a;

  for (;;) {
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;

    int now = 0, ans = 0;

    for (int i = 0; i < n; i++)
      cin >> map[i];

    for (int i = 0; i < m; i++) {
      cin >> a;
      now += a;
      if (map[now] != 0 && ans == 0)
        now += map[now];
      if (now >= n - 1 && ans == 0)
        ans = i + 1;
    }
    cout << ans << endl;
  }
}

Error: 0

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int n, m;
  int map[3000] = {0};
  int a;

  for (;;) {
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;

    int now = 0, ans = 0;

    for (int i = 0; i < n; i++)
      cin >> map[i];

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

#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
#define INF 100000000
using namespace std;
typedef pair<int, int> P;
int S[1001];
int main() {
  int n, m, ans;
  while (cin >> n >> m && (n != 0 || m != 0)) {
    for (int i = 1; i <= n; i++)
      cin >> S[i];
    int pos = 1;
    for (ans = 1; ans <= m; ans++) {
      int d;
      cin >> d;
      pos += d;
      if (pos >= n)
        break;
      pos += S[pos];
      if (pos >= n)
        break;
    }
    for (int i = ans; i < m; i++)
      cin >> n;
    cout << ans << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
#define INF 100000000
using namespace std;
typedef pair<int, int> P;
int S[1000];
int main() {
  int n, m, ans;
  while (cin >> n >> m && (n || m)) {
    for (int i = 0; i < n; i++)
      cin >> S[i];
    int pos = 1;
    for (ans = 1; ans <= m; ans++) {
      int d;
      cin >> d;
      pos += d;
      if (pos >= n)
        break;
      pos += S[pos];
      if (pos >= n)
        break;
    }
    cout << ans << endl;
  }
}
Problem p00467 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int n, m, cnt = 0, end = 0, sai, now = 0, mass[1001];
  while (true) {
    cin >> n >> m;
    if (n == 0 && m == 0) {
      break;
    }
    for (int i = 0; i < n; i++) {
      cin >> mass[i];
    }

    for (int i = 0; i < m; i++) {
      cin >> sai;
      if (end == 0) {
        now += sai;
        now += mass[now];
        cnt++;
      }
      if (now >= n) {
        end = 1;
      }
    }
    cout << cnt << endl;
    cnt = 0;
    end = 0;
    now = 0;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, m, x, now = 1, flag = 0, index, cnt = 0;
  while (true) {
    if (n == 0 && m == 0) {
      break;
    }

    cin >> n >> m;
    int mass[n];

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

    for (int j = 0; j < n; j++) {
      while (now < n) {
        cin >> index;
        now = now + index;
        x = mass[now - 1];
        now += x;
        if (flag == 0) {
          cnt++;
        }
      }
    }

    cout << cnt << endl;
    now = 1;
    flag = 0;
    cnt = 0;
    for (int i = 0; i < n; i++) {
      mass[i] = 0;
    }
  }
}
Problem p00467 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define mp make_pair

template <class T> void pv(T a, T b) {
  for (T i = a; i != b; ++i)
    cout << *i << " ";
  cout << endl;
}
template <class T> void chmin(T &t, T f) {
  if (t > f)
    t = f;
}
template <class T> void chmax(T &t, T f) {
  if (t < f)
    t = f;
}
int in() {
  int x;
  scanf("%d", &x);
  return x;
}

int sugoroku[1010];

int main() {
  int n, m;
  while (n = in(), m = in()) {
    int i;
    for (i = 1; i <= n; i++) {
      cin >> sugoroku[i];
    }
    int nw = 1;
    int res = -1;
    for (i = 1; i <= m; i++) {
      if (res == -1) {
        nw += in();
        if (nw >= n && res == -1) {
          res = i;
          continue;
        }
        nw += sugoroku[nw];
        if (nw >= n && res == -1)
          res = i;
      } else
        in();
    }
    cout << res << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define mp make_pair

template <class T> void pv(T a, T b) {
  for (T i = a; i != b; ++i)
    cout << *i << " ";
  cout << endl;
}
template <class T> void chmin(T &t, T f) {
  if (t > f)
    t = f;
}
template <class T> void chmax(T &t, T f) {
  if (t < f)
    t = f;
}
int in() {
  int x;
  scanf("%d", &x);
  return x;
}

int sugoroku[1010];

int main() {
  int n, m;
  while (n = in(), m = in()) {
    int i;
    for (i = 1; i <= n; i++) {
      cin >> sugoroku[i];
    }
    int nw = 1;
    int res = -1;
    for (i = 1; i <= m; i++) {
      nw += in();
      if (nw >= n && res == -1)
        res = i;
      nw += sugoroku[nw];
      if (nw >= n && res == -1)
        res = i;
    }
    cout << res << endl;
  }
  return 0;
}
Problem p00467 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

using namespace std;

int main() {

  int n, m;

  vector<int> board, dice;
  int pos;
  int turn;
  int move;

  while (cin >> n >> m) {

    if (n == 0 && m == 0)
      break;

    board.clear();

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

      int tmp;

      cin >> tmp;

      board.push_back(tmp);
    }

    // for(int i=0;i<n;i++) cout << board[i] << " ";

    dice.clear();

    for (int i = 0; i < m; i++) {

      int tmp;

      cin >> tmp;

      dice.push_back(tmp);
    }

    pos = 1;

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

      move = dice[turn - 1];

      pos += move;

      if (pos >= n)
        break;

      pos += board[pos - 1];

      if (pos >= n)
        break;
    }

    cout << turn << endl;
  }

  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int main() {

  int n, m;

  vector<int> board;
  int pos;
  int turn;
  int move;

  while (cin >> n >> m) {

    if (n == 0 && m == 0)
      break;

    board.clear();

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

      int tmp;

      cin >> tmp;

      board.push_back(tmp);
    }

    for (int i = 0; i < n; i++)
      cout << board[i] << " ";

    pos = 1;

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

      cin >> move;

      pos += move;

      if (pos >= n)
        break;

      pos += board[pos - 1];

      if (pos >= n)
        break;
    }

    cout << turn << endl;
  }

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

#include <bits/stdc++.h>
using namespace std;

int main() {

  int N, M;
  int masu[1005], me[1005];
  int cntmemasu, jj, cnt;

  while (1) {
    cntmemasu = 1;
    jj = 0;
    cnt = 1;
    cin >> N >> M;
    if (N == 0 && M == 0)
      break;
    for (int i = 1; i <= N; i++) {
      cin >> masu[i];
    }

    for (int i = 1; i <= M; i++) {
      cin >> me[i];
    }

    for (int j = 1; j <= M; j++) {
      jj++;
      cntmemasu += me[j];
      cnt = cntmemasu;
      // cout << cnt << " ";
      if (cntmemasu >= N) {
        cout << jj << endl;
        break;
      }
      cntmemasu += masu[cnt];
      cnt = cntmemasu;
      //  cout << cnt << " ";
      if (cntmemasu >= N) {
        cout << jj << endl;
        break;
      }
    }
  }
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {

  int N, M;
  int masu[1001], me[1001];
  int cnt = 0, cntmemasu = 1, j;

  cin >> N >> M;

  for (int i = 1; i <= N; i++) {
    cin >> masu[i];
  }

  for (int i = 1; i <= M; i++) {
    cin >> me[i];
  }
  j = 1;
  while (1) {
    if (cntmemasu == N)
      break;
    cntmemasu += me[j];
    // cnt+=me[j];
    cntmemasu += masu[cntmemasu];
    j++;
    // cout << cntmemasu << " " ;
  }
  /* for(int i = 1; i <= N; i++){
   cout << masu[i];
  }

  for(int i = 1; i <= M; i++){
    cout << me[i];
    }*/

  cout << j - 1 << endl;

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

#include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

int main() {
  int n, m;

  while (cin >> n >> m, n + m) {
    int s[2000] = {0}, tmp[m + 1], p = 0, cnt = 0;
    REP(i, n) cin >> s[i];
    REP(i, m) cin >> tmp[i];
    REP(i, m) {
      if (p <= n - 1) {
        cnt++;
      } else
        break;
      p += tmp[i];
      p += s[p];
    }
    cout << cnt << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

int main() {
  int n, m;

  while (cin >> n >> m, n + m) {
    int s[2005] = {0}, p = 0, cnt = 0;

    REP(i, n) cin >> s[i];
    REP(i, m) {
      if (p <= n - 1)
        cnt++;
      int tmp;
      cin >> tmp;
      p += tmp;
      p += s[p];
    }
    cout << cnt << endl;
  }
}
Problem p00467 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int n, m, k, a[114514], ans;
void check(int i) {
  if (k >= n)
    if (ans == 114514)
      ans = i;
  return;
}
int main() {
  while (cin >> n >> m) {
    if (!m && !n)
      return 0;
    for (int i = 1; i <= n; i++)
      cin >> a[i];
    k = 1;
    ans = 114514;
    for (int i = 1; i <= m; i++) {
      int s;
      cin >> s;
      if (ans == 114514)
        k += s;
      check(i);
      if (ans == 114514)
        k += a[k];
      check(i);
    }
    cout << ans << endl;
  }
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int n, m;
  while (cin >> n >> m) {
    if (n == 0 && m == 0)
      return 0;
    int s[1010] = {0};
    for (int i = 0; i < n; i++) {
      cin >> s[i];
    }
    int g = 0;        // genzaiti
    int sum = 0;      // kaisu
    bool b00l = true; // true:?????? false:?±????
    for (int i = 0; i < m; i++) {
      int a;
      cin >> a;
      if (b00l && g >= n)
        b00l = false;
      else {
        g += a;
        sum++;
        if (b00l) {
          if (g >= n) {
            b00l = false;
          }
        } else
          g += s[g];
      }
    }
    cout << sum << endl;
  }
}
Problem p00467 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int pos = 0;
  int n, m;
  int cnt = 0;
  int array[n];
  while (cin >> n >> m) {
    if (n == 0)
      break;
    cnt = 0;
    pos = 0;
    for (int i = 0; i < n; i++) {
      cin >> array[i];
    }
    for (int i = 0; i < m; i++) {
      int tmp;
      cin >> tmp;
      if (pos < n) {
        pos += tmp;
        pos += array[pos];
        cnt++;
      }
    }
    cout << cnt << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int pos = 0;
  int n, m;
  int cnt = 0;
  while (cin >> n >> m, n) {
    int array[n];
    cnt = 0;
    pos = 0;
    for (int i = 0; i < n; i++) {
      cin >> array[i];
    }
    for (int i = 0; i < m; i++) {
      int tmp;
      cin >> tmp;
      if (pos < n) {
        pos += tmp;
        pos += array[pos];
        cnt++;
      }
    }
    cout << cnt << endl;
  }
  return 0;
}