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

#include <iostream>
#define MAX 100500

using namespace std;

int main(void) {

  int n, m;
  long long int N, M[MAX], d[MAX];

  while (cin >> n) {

    cin >> m;

    for (int i = 0; i < MAX; i++) {
      M[i] = 0;
      d[i] = 0;
    }

    d[0] = 0;

    for (int i = 1; i < n; i++) {
      cin >> N;
      d[i] += d[i - 1] + N;
      //  cout << "N = " << N << " d[i] = " << d[i] << endl;
    }

    for (int i = 0; i < m; i++)
      cin >> M[i];

    long long int sum = 0, now = 0;

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

      // cout << endl << "i = " << i << " now = "  << now << endl;//

      //  cout <<"now + M[i] = " << now + M[i]<<   " d[now + M[i]] = " << d[now
      //  + M[i]] << " d[now] =  " <<  d[now] << endl;//

      if (M[i] >= 0) {
        sum += d[now + M[i]] - d[now];
        //	cout << "! N = " << d[now + M[i]] - d[now] << endl;//
      } else {
        sum += d[now] - d[now + M[i]];
        //	cout << "? N = " <<  d[now] - d[now + M[i]]  << endl;//
      }

      now = now + M[i]; //
    }
    cout << sum % 100000 << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main(void) {

  int n, m;
  long long int N[MAX], M[MAX];

  while (cin >> n) {

    cin >> m;

    for (int i = 0; i < MAX; i++) {
      N[i] = 0;
      M[i] = 0;
    }

    for (int i = 0; i < n - 1; i++) {
      cin >> N[i];
    }
    for (int i = 0; i < m; i++)
      cin >> M[i];

    long long int sum = 0, now = 0;

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

      // cout << endl << "i = " << i << " now = "  << now << endl;

      if (M[i] >= 0) {
        for (int j = now; j < now + M[i]; j++) {
          sum += N[j];
          //	  cout << "N = " << N[j] << endl;//
        }
      } else {
        for (int j = now - 1; j > now + M[i] - 1; j--) {
          sum += N[j];
          //	  cout << "N = " << N[j] << endl;//
        }
      }

      now = now + M[i]; //
    }
    cout << sum % 100000 << endl;
  }

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

#include <cstdio>
#include <cstdlib>
using namespace std;

typedef unsigned long long int ulln;

int main(void) {
  int m, n;
  int dist[100001] = {0};
  scanf("%d%d", &m, &n);

  int s;
  for (int i = 0; i < m - 1; i++) {
    scanf("%d", &s);
    dist[i + 1] = dist[i] + s;
  }

  int a, cur = 0;
  ulln ans = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a);
    ans += (ulln)abs(dist[cur] - dist[cur + a]);
    cur += a;
  }
  printf("%d\\n", ans % 100000);
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
int main(void) {
  int n, m;
  scanf("%d%d", &n, &m);
  int current = 0, ans = 0;
  int dist[100000] = {0}, plan[100000] = {0};
  for (int i = 0; i < n - 1; i++)
    scanf("%d", &dist[i]);
  for (int i = 0; i < m; i++)
    scanf("%d", &plan[i]);

  for (int i = 0; i < m; i++) {
    if (plan[i] > 0)
      for (int j = 0; j < plan[i]; j++) {
        ans = (ans + dist[current + j]) % 100000;
      }
    else
      for (int j = 0; j < abs(plan[i]); j++) {
        ans = (ans + dist[current - j - 1]) % 100000;
      }
    current += plan[i];
  }

  printf("%d\\n", ans);

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

#include <stdio.h>
int main(void) {
  int n, m, t[100001], s[100001], i, j, ans = 0, from, to;
  from = 0;
  scanf("%d%d", &n, &m);
  n--;
  for (i = 0; i < n; i++) {
    scanf("%d", &s[i]);
    t[i] = 0;
  }
  for (i = 0; i < m; i++) {
    scanf("%d", &to);
    to += from;
    if (to > from) {
      for (j = from; j < to; j++) {
        t[j]++;
      }
    } else {
      for (j = to; j < from; j++) {
        t[j]++;
      }
    }
    from = to;
  }
  for (i = 0; i < n; i++) {
    ans += s[i] * t[i];
    ans %= 100000;
  }
  printf("%d\\n", ans);
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
int main(void) {
  int n, m, a[100001], s[100001], i, j, ans = 0;
  a[0] = 0;
  scanf("%d%d", &n, &m);
  n--;
  for (i = 0; i < n; i++) {
    scanf("%d", &s[i]);
  }
  for (i = 1; i <= m; i++) {
    scanf("%d", &a[i]);
    a[i] += a[i - 1];
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (a[j] > i && a[j + 1] <= i) {
        ans += s[i];
      } else if (a[j + 1] > i && a[j] <= i) {
        ans += s[i];
      }
      ans %= 100000;
    }
  }
  printf("%d\\n", ans);
  return 0;
}
Problem p00472 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int a[100000], cnt[100000];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n - 1; i++) {
    cin >> a[i];
    cnt[i] = 0;
  }
  int bef, now, z;
  cin >> bef;
  now = bef;
  for (int i = 0; i < bef; i++)
    cnt[i]++;
  for (int i = 0; i < m - 1; i++) {
    cin >> z;
    now += z;
    if (bef < now)
      for (int j = bef; j < now; j++)
        cnt[j]++;
    if (bef > now)
      for (int j = now; j < bef; j++)
        cnt[j]++;
    bef = now;
  }
  int ans = 0;
  for (int i = 0; i < n - 1; i++) {
    ans += cnt[i] * a[i] % 100000;
    ans %= 100000;
  }
  cout << ans << endl;
  return 0;
}

Error: -6
terminate called after throwing an instance of 'std::__ios_failure'
  what():  basic_ios::clear: iostream error


Fixed submission:

#include <iostream>
using namespace std;
int a[100000], cnt[100000];
int main() {
  int n, m;
  while (true) {
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    for (int i = 0; i < n - 1; i++) {
      cin >> a[i];
      cnt[i] = 0;
    }
    int bef, now, z;
    cin >> bef;
    now = bef;
    for (int i = 0; i < bef; i++)
      cnt[i]++;
    for (int i = 0; i < m - 1; i++) {
      cin >> z;
      now += z;
      if (bef < now)
        for (int j = bef; j < now; j++)
          cnt[j]++;
      if (bef > now)
        for (int j = now; j < bef; j++)
          cnt[j]++;
      bef = now;
    }
    int ans = 0;
    for (int i = 0; i < n - 1; i++) {
      ans += cnt[i] * a[i] % 100000;
      ans %= 100000;
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00472 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <cstdlib>
using namespace std;

int main(void) {
  int mm = 0;
  int nn = 0;
  scanf("%d", &nn);
  scanf("%d", &mm);
  int i = 0;
  int n[100005] = {0};
  for (i = 1; i < nn; i++) {
    scanf("%d", &(n[i]));
    n[i] += n[i - 1];
  }
  int ans = 0;
  int im = 0;
  int is = 0;
  for (i = 0; i < mm; i++) {
    scanf("%d", &(im));
    im += is;
    ans = (abs(n[im] - n[is]) + ans) % 100000;
    is = im;
  }
  printf("%d\\n", ans);
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
using namespace std;

int main(void) {
  int mm = 0;
  int nn = 0;
  scanf("%d", &nn);
  scanf("%d", &mm);
  int i = 0;
  int n[100000] = {0};
  int m[100000] = {0};
  for (i = 0; i < nn - 1; i++) {
    scanf("%d", &(n[i]));
  }
  /*for(i=0;i<mm;i++){
    scanf("%d",&(m[i]));
  }*/
  int ans = 0;
  int im = 0;
  int is = 0;
  for (i = 0; i < mm; i++) {
    scanf("%d", &(im));
    // im+=m[i];
    im += is;
    // if(m[i]>0){
    if (im - is > 0) {
      while (is != im) {
        ans = ((ans + (n[is] % 100000)) % 100000);
        is++;
      }
    } else {
      while (is != im) {
        is--;
        ans = ((ans + (n[is] % 100000)) % 100000);
      }
    }
  }
  printf("%d\\n", ans);
  return 0;
}
Problem p00472 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, init, n) for (int i = init; i < (n); i++)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct {
  int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
  int N, M;
  cin >> N >> M;

  vector<ll> dist(100000, 0);

  dist[0] = 0;

  REP(i, 1, N) {
    int input;
    cin >> input;
    dist[i] = dist[i - 1] + input;
  }

  int now = 0, ans = 0;

  rep(i, M) {
    int input;
    cin >> input;

    ans = (ans + abs(dist[now + input] - dist[now])) % 100000;
    now += input;
  }

  cout << ans % 100000 << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, init, n) for (int i = init; i < (n); i++)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct {
  int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
  int N, M;
  cin >> N >> M;

  vector<int> dist(N, 0);

  rep(i, N - 1) {
    int input;
    cin >> input;
    dist[i + 1] = input;
  }

  rep(i, N) dist[i + 1] += dist[i];

  int now = 0, ans = 0;

  rep(i, M) {
    int input;
    cin >> input;

    ans += abs(dist[now + input] - dist[now]);
    now += input;
  }

  cout << ans % 100000 << endl;

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

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
int n, m;
int i, j;
int d[100000];
int main() {
  scanf("%d %d", &n, &m);
  d[0] = 0;
  int x;
  for (i = 0; i < n - 1; i++) {
    scanf("%d", &x);
    d[i + 1] = d[i] + x;
  }
  int ans = 0;
  int pos = 0;
  for (i = 0; i < m; i++) {
    scanf("%d", &x);
    ans = (ans + abs(d[pos + x] - d[pos])) % 100000;
    pos += x;
  }
  printf("%d\\n", ans);
}

Error: TLE

Fixed submission:

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
int n, m;
int i, j;
int d[100000];
int main() {
  while (1) {
    scanf("%d %d", &n, &m);
    if (n == 0)
      return 0;
    d[0] = 0;
    int x;
    for (i = 0; i < n - 1; i++) {
      scanf("%d", &x);
      d[i + 1] = d[i] + x;
    }
    int ans = 0;
    int pos = 0;
    for (i = 0; i < m; i++) {
      scanf("%d", &x);
      ans += abs(d[pos + x] - d[pos]);
      pos += x;
    }
    printf("%d\\n", ans);
  }
}
Problem p00472 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define INF 1e+8
#define rep(i, j) for (int i = 0; i < (j); i++)
#define reps(i, j, k) for (int i = j; i < k; i++)
typedef long long ll;
typedef unsigned long long ull;

int main() {
  int n, m;
  int field[128000] = {0};
  scanf("%d%d", &n, &m);
  rep(i, n - 1) { scanf("%d", &field[i]); }
  int mod = 100000;
  int res = 0;
  int now = 0;
  rep(i, m) {
    int x;
    int j;
    scanf("%d", &x);
    if (x > 0) {
      for (j = now; j < now + x; j++) {
        if (res + field[j] >= mod)
          res = (res + field[j]) % mod;
        else
          res += field[j];
      }
      now += x;
    } else {
      for (j = now - 1; j > now + x - 1; j--) {
        if (res + field[j] >= mod)
          res = (res + field[j]) % mod;
        else
          res += field[j];
      }
      now += x;
    }
  }
  printf("%d\\n", res);
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define INF 1e+8
#define rep(i, j) for (int i = 0; i < (j); i++)
#define reps(i, j, k) for (int i = j; i < k; i++)
typedef long long ll;
typedef unsigned long long ull;

int main() {
  int n, m;
  int field[128000] = {0};
  scanf("%d%d", &n, &m);
  rep(i, n - 1) { scanf("%d", &field[i]); }
  int mod = 100000;
  int res = 0;
  int now = 0;
  rep(i, m) {
    int x;
    int j;
    scanf("%d", &x);
    if (x > 0) {
      for (j = now; j < now + x; j++) {
        if (res + field[j] > mod)
          res -= mod;
        res += field[j];
      }
      now += x;
    } else {
      for (j = now - 1; j > now + x - 1; j--) {
        if (res + field[j] > mod)
          res -= mod;
        res += field[j];
      }
      now += x;
    }
  }
  printf("%d\\n", res);
  return 0;
}
Problem p00472 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
int main(void) {
  int n, m, s, w = 0;
  unsigned int cnt = 0;
  short a[100000];
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n - 1; i++) {
    scanf("%d", &s);
    a[i] = s;
  }
  for (int i = 0; i < m; i++) {
    scanf("%d", &s);
    for (int j = 0; j < s; j++) {
      cnt += a[w++];
    }
    for (int j = 0; j > s; j--) {
      cnt += a[--w];
    }
    cnt %= 100000;
  }

  printf("%d\\n", cnt);
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
int main(void) {
  int n, m, s, w = 0;
  double cnt = 0;
  short a[100000];
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n - 1; i++) {
    scanf("%d", &s);
    a[i] = s;
  }
  for (int i = 0; i < m; i++) {
    scanf("%d", &s);
    for (int j = 0; j < s; j++) {
      cnt += a[w++];
      //	cnt%=100000;
    }
    for (int j = 0; j > s; j--) {
      cnt += a[--w];
      //	cnt%=100000;
    }
  }

  printf("%d\\n", (int)cnt % 100000);
  return 0;
}
Problem p00472 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define FOR(i, k, n) for (int i = (k); i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define FORIT(i, c)                                                            \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)

int main() {
  int n, m;
  int a[100000];
  int now = 0;
  int ans = 0;
  cin >> n >> m;
  REP(i, n - 1) {
    int tmp;
    cin >> tmp;
    a[i + 1] = a[i] + tmp;
  }
  REP(i, m) {
    int d;
    cin >> d;
    ans = (ans + abs(a[now] - a[now + d])) % 100000;
    now += d;
  }
  cout << ans << endl;
  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define FOR(i, k, n) for (int i = (k); i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define FORIT(i, c)                                                            \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)

int main() {
  int n, m;
  vector<int> a(n);
  int now = 0;
  int ans = 0;
  cin >> n >> m;
  REP(i, n - 1) {
    int tmp;
    cin >> tmp;
    a[i + 1] = a[i] + tmp;
  }
  REP(i, m) {
    int d;
    cin >> d;
    ans = (ans + abs(a[now] - a[now + d])) % 10000;
    now += d;
  }
  cout << ans << endl;
  return 0;
}
Problem p00472 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>

using namespace std;

int main(void) {
  int n, m;

  while (scanf("%d%d", &n, &m) != EOF) {

    long long s[100001] = {0};
    int a[100001];

    for (int i = 2; i <= n; i++) {
      scanf("%lld", &s[i]);
      s[i] += s[i - 1];
    }

    for (int i = 0; i < m; i++) {
      scanf("%d", &a[i]);
    }

    //		for(int i = 1; i < n; i++)printf("%2d ",s[i]);
    //		puts("");

    int br = 1;
    int ar = 1;
    long long ans = 0;

    for (int i = 0; i < m; i++) {
      ar = br + a[i];
      if (a[i] < 0)
        swap(ar, br);

      ans += s[ar] - s[br];
      ans %= 100000;
      if (a[i] < 0)
        swap(ar, br);
      //			printf("day %.0lf : %d km\\n",i,ans);
      //			printf("%d -> %d\\n", br, ar);

      br = ar;
    }
    printf("%lld\\n", ans);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>

using namespace std;

int main(void) {
  int n, m;

  while (scanf("%d%d", &n, &m) != EOF) {

    int s[100001];
    int a[100001];

    for (int i = 1; i < n; i++) {
      scanf("%d", &s[i]);
    }

    for (int i = 0; i < m; i++) {
      scanf("%d", &a[i]);
    }

    int br = 1;
    int ar = 1;
    int ans = 0;

    for (int i = 0; i < m; i++) {
      ar = br + a[i];
      if (a[i] < 0)
        swap(ar, br);
      for (int i = br; i < ar; i++)
        ans = (ans + s[i]) % 100000;
      if (a[i] < 0)
        swap(ar, br);
      //			printf("day %d : %d km\\n",i,ans);
      //			printf("%d -> %d\\n", br, ar);

      br = ar;
    }

    printf("%d\\n", ans);
  }
  return 0;
}
Problem p00472 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define FOR(i, n) for (int i = 0; i < (int)(n); i++)
#define FORR(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define pb(a) push_back(a)
#define ZERO(a) memset(a, 0, sizeof(a))
#define len(a) sizeof(a)
#define ll long long
#define INF 1 << 29
#define MAX 101010
#define MOD 100000
using namespace std;

int s[MAX], sum[MAX];

void solve() {
  int n, m, a;
  cin >> n >> m;
  FOR(i, n - 1) cin >> s[i];
  int from = 0, to;
  ZERO(sum);
  FOR(i, m) {
    cin >> a;
    to = from + a;
    sum[max(from, to)]--;
    sum[min(from, to)]++;
    from = to;
  }
  int ans = 0;
  FOR(i, n - 1) {
    sum[i + 1] += sum[i];
    ans = (ans + sum[i] * s[i]) % MOD;
  }
  cout << ans << endl;
}

int main() {
  solve();
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define FOR(i, n) for (int i = 0; i < (int)(n); i++)
#define FORR(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define pb(a) push_back(a)
#define ZERO(a) memset(a, 0, sizeof(a))
#define len(a) sizeof(a)
#define ll long long
#define INF 1 << 29
#define MAX 101010
#define MOD 100000
using namespace std;

int s[MAX], sum[MAX];

void solve() {
  int n, m, a;
  for (;;) {
    cin >> n >> m;
    if (!n)
      break;
    FOR(i, n - 1) cin >> s[i];
    int from = 0, to;
    ZERO(sum);
    FOR(i, m) {
      cin >> a;
      to = from + a;
      sum[max(from, to)]--;
      sum[min(from, to)]++;
      from = to;
    }
    int ans = 0;
    FOR(i, n - 1) {
      sum[i + 1] += sum[i];
      ans = (ans + sum[i] * s[i]) % MOD;
    }
    cout << ans << endl;
  }
}

int main() {
  solve();
  return 0;
}
Problem p00472 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctime>
#include <fstream>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define REP(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define MSG(a) cout << #a << " " << a << 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;
}

const int MOD = 100000;

int main() {
  // ifstream ifs("E:\\\\programing\\\\C
  // C++\\\\2010-ho-data\\\\2010-ho-data\\\\2010-ho-t1-in6");
  int n, m;
  while (cin >> n >> m) {
    int index = 0, res = 0;
    vint town(n);
    town[0] = 0;

    REP(i, 1, n)
    cin >> town[i];

    partial_sum(town.begin(), town.end(), town.begin());

    rep(i, m) {
      int s;
      cin >> s;

      res += abs(town[index] - town[index + s]);
      index += s;
      res %= MOD;
    }

    cout << res << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctime>
#include <fstream>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define REP(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define MSG(a) cout << #a << " " << a << 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;
}

const int MOD = 100000;

int main() {
  int n, m;
  while (cin >> n >> m) {
    int index = 0, res = 0;
    vint town(n);

    rep(i, n - 1) cin >> town[i];

    rep(i, m) {
      int s;
      cin >> s;

      int d = s / abs(s);
      for (int j = index; j != index + s; j += d) {
        res += town[(d < 0 ? j - 1 : j)];
      }
      index += s;
      res %= MOD;
    }

    cout << res << endl;
  }
}
Problem p00472 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (long long i = (a); i < (b); i++)
#define REP(i, N) for (long long i = 0; i < (N); i++)
#define ALL(s) (s).begin(), (s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_N 20000
#define MAX_M 16

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n, m;
int s[100100];
int a;

int main() {
  cin >> n >> m;
  int ans = 0;
  s[1] = 0;
  FOR(i, 2, n + 1) cin >> s[i];
  FOR(i, 1, n + 1) s[i + 1] += s[i];
  int now = 1;
  REP(i, m) {
    cin >> a;
    ans = (ans + abs(s[now + a] - s[now])) % 100000;
    now += a;
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (long long i = (a); i < (b); i++)
#define REP(i, N) for (long long i = 0; i < (N); i++)
#define ALL(s) (s).begin(), (s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_N 20000
#define MAX_M 16

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n, m;
int s[100001];
int a;

int main() {
  cin >> n >> m;
  int ans = 0;
  s[1] = 0;
  FOR(i, 2, n + 1) cin >> s[i];
  FOR(i, 1, n + 1) s[i + 1] += s[i];
  int now = 1;
  REP(i, m) {
    cin >> a;
    ans = (ans + abs(s[now + a] - s[now])) % 100000;
    now += a;
  }
  cout << ans << endl;
}