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

#include <algorithm>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define INF 100000000
#define mod 100000
typedef long long int lli;
typedef pair<int, int> P;

int s[100000];
int a[100000];
int cnt[100000];

int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i < n; ++i) {
    cin >> s[i];
  }
  for (int i = 1; i <= m; ++i) {
    cin >> a[i];
  }
  long long int ans = 0;
  int town = 1;
  for (int i = 1; i < n; ++i) {
    cnt[i] = 0;
  }
  for (int i = 1; i <= m; ++i) {
    if (a[i] < 0) {
      for (int j = town - 1; j >= town + a[i]; --j) {
        // ans+=s[j]%mod;
        ++cnt[j];
      }
    } else {
      for (int j = town; j < town + a[i]; ++j) {
        // ans+=s[j]%mod;
        ++cnt[j];
      }
    }
    town += a[i];
  }
  for (int i = 1; i < n; ++i) {
    ans += s[i] * cnt[i] % mod;
  }
  cout << ans % mod << "\\n";
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define INF 100000000
#define mod 100000
typedef long long int lli;
typedef pair<int, int> P;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(n);
  for (int i = 1; i < n; ++i) {
    cin >> s[i];
  }
  vector<int> a(m + 1);
  for (int i = 1; i <= m; ++i) {
    cin >> a[i];
  }
  long long int ans = 0;
  int town = 1;
  for (int i = 1; i <= m; ++i) {
    if (a[i] < 0) {
      for (int j = town - 1; j >= town + a[i]; --j) {
        ans += s[j] % mod;
      }
    } else {
      for (int j = town; j < town + a[i]; ++j) {
        ans += s[j] % mod;
      }
    }
    town += a[i];
  }
  cout << ans % mod << "\\n";
}
Problem p00472 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;

static const double EPS = 1e-8;

static const int tx[] = {0, 1, 0, -1};
static const int ty[] = {-1, 0, 1, 0};

int main() {
  int total_post_towns;
  int total_journey_days;
  while (~scanf("%d %d", &total_post_towns, &total_journey_days)) {
    vector<int> path;

    int sum[100001];
    memset(sum, 0, sizeof(sum));
    for (int i = 0; i < total_post_towns - 1; i++) {
      int distance;
      scanf("%d", &distance);
      path.push_back(distance);
      sum[i + 1] = distance + sum[i];
    }

    int sx = 0;
    int res = 0;
    for (int i = 0; i < total_journey_days; i++) {
      int dx;
      scanf("%d", &dx);
      if (dx < 0) {
        res += sum[sx] - sum[sx + dx];
        res %= 100000;
        sx += dx;
      } else if (dx >= 0) {
        res += sum[sx + dx] - sum[sx];
        res %= 100000;
        sx += dx;
      }
    }

    printf("%d\\n", res % 100000);
  }
}

Error: TLE

Fixed submission:

#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;

static const double EPS = 1e-8;

static const int tx[] = {0, 1, 0, -1};
static const int ty[] = {-1, 0, 1, 0};

int main() {
  int total_post_towns;
  int total_journey_days;
  while (~scanf("%d %d", &total_post_towns, &total_journey_days)) {
    vector<int> path;
    for (int i = 0; i < total_post_towns - 1; i++) {
      int distance;
      scanf("%d", &distance);
      path.push_back(distance);
    }

    int sx = 0;

    int sum = 0;
    for (int i = 0; i < total_journey_days; i++) {
      int dx;
      scanf("%d", &dx);
      if (dx < 0) {
        for (int x = sx - 1; x >= sx + dx; x--) {
          sum += path[x] % 100000;
          sum %= 100000;
        }
        sx += dx;
      } else if (dx >= 0) {
        for (int x = sx; x < sx + dx; x++) {
          sum += path[x] % 100000;
          sum %= 100000;
        }
        sx += dx;
      }
    }

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

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

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const int INF = 1 << 29;
const double EPS = 1e-9;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int n, m;
int hotel[100010];
int d;
int main() {
  cin >> n >> m;
  hotel[0] = 0;
  hotel[1] = 0;
  for (int i = 1; i <= n - 1; i++) {
    cin >> d;
    hotel[i + 1] = hotel[i] + d;
  }
  int pos = 1;
  long long sum = 0;
  for (int i = 0; i < m; i++) {
    cin >> d;
    sum += abs(hotel[pos + d] - hotel[pos]);
    sum = sum % 100000;
    pos = pos + d;
  }
  cout << sum << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const int INF = 1 << 29;
const double EPS = 1e-9;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int n, m;
int hotel[100010];
int d;
int main() {
  while (cin >> n >> m, n || m) {
    hotel[0] = 0;
    hotel[1] = 0;
    fill(hotel, hotel + 100010, 0);
    for (int i = 1; i <= n - 1; i++) {
      cin >> d;
      hotel[i + 1] = hotel[i] + d;
    }
    int pos = 1;
    int sum = 0;
    for (int i = 0; i < m; i++) {
      cin >> d;
      sum += abs(hotel[pos + d] - hotel[pos]) % 100000;
      pos = pos + d;
    }
    cout << sum << endl;
  }
  return 0;
}
Problem p00472 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

#define MAX_N (1 << 18)
#define N 100000
#define mod 100000

class Range {
  int data[MAX_N];
  int n;

public:
  void init(int pn) {
    n = 1;
    while (n < pn)
      n <<= 1;
    for (int i = 0; i < 2 * n; ++i)
      data[i] = 0;
  }

  void add(int k, int a) {
    k += n - 1;

    while (k) {
      data[k] = (data[k] + a) % mod;
      k = (k - 1) / 2;
    }
    data[0] = (data[0] + a) % mod;
  }

  int query(int a, int b, int l, int r, int k) {
    if (r <= a || b <= l)
      return 0;
    int sum = 0;
    if (a <= l && r <= b)
      return data[k];
    sum += query(a, b, l, (l + r) / 2, 2 * k + 1);
    sum += query(a, b, (l + r) / 2, r, 2 * k + 2);
    return sum % mod;
  }

  int sum(int a, int b) { return query(a, b, 0, n, 0); }
};

int main() {
  int n, m;
  Range r;
  int s, a, ans = 0;
  cin >> n >> m;
  r.init(n - 1);
  for (int i = 0; i < n - 1; ++i) {
    cin >> s;
    r.add(i, s);
  }
  int pos = 0;
  for (int i = 0; i < m; ++i) {
    cin >> a;
    if (a > 0) {
      ans = (ans + r.sum(pos, pos + a)) % mod;
    } else if (a < 0) {
      ans = (ans + r.sum(pos + a, pos)) % mod;
    }
    pos += a;
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

#define MAX_N (1 << 16)
#define N 100000
#define mod 100000

class Range {
  int data[MAX_N];
  int n;

public:
  void init(int pn) {
    n = 1;
    while (n < pn)
      n <<= 1;
    for (int i = 0; i < 2 * n; ++i)
      data[i] = 0;
  }

  void add(int k, int a) {
    k += n - 1;

    while (k) {
      data[k] = (data[k] + a) % mod;
      k = (k - 1) / 2;
    }
    data[0] = (data[0] + a) % mod;
  }

  int query(int a, int b, int l, int r, int k) {
    if (r <= a || b <= l)
      return 0;
    int sum = 0;
    if (a <= l && r <= b)
      return data[k];
    sum += query(a, b, l, (l + r) / 2, 2 * k + 1);
    sum += query(a, b, (l + r) / 2, r, 2 * k + 2);
    return sum % mod;
  }

  int sum(int a, int b) { return query(a, b, 0, n, 0); }
};

int main() {
  int n, m;
  Range r;
  int s, a, ans = 0;
  cin >> n >> m;
  r.init(n - 1);
  for (int i = 0; i < n - 1; ++i) {
    cin >> s;
    r.add(i, s);
  }
  int pos = 0;
  for (int i = 0; i < m; ++i) {
    cin >> a;
    if (a > 0) {
      ans = (ans + r.sum(pos, pos + a)) % mod;
    } else if (a < 0) {
      ans = (ans + r.sum(pos + a, pos)) % mod;
    }
    pos += a;
  }
  cout << ans << endl;
  return 0;
}
Problem p00472 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm> // require sort next_permutation count etc.
#include <cctype>    // require tolower, toupper
#include <cfloat>
#include <climits> // require INT_MAX etc
#include <cmath>   // require sqrt ceil floor
#include <cstdio>  // require printf
#include <cstdlib> // require abs
#include <cstring> // require memset
#include <deque>
#include <fstream> // require freopen
#include <functional>
#include <iomanip> // require setw
#include <iostream>
#include <limits>
#include <map>
#include <numeric> // require accumulate
#include <queue>
#include <set>
#include <sstream> // require stringstream
#include <stack>
#include <stdint.h> // require uint64_t
#include <string>
#include <vector>

using namespace std;

const int M = 100000;

int main() {
  //	cut here before submit
  //	freopen ("testcase.traveler", "r", stdin );
  int n, m;

  while (cin >> n >> m && n && m) {
    vector<int> d(n, 0);
    for (int i = 0; i < n - 1; ++i) {
      cin >> d[i];
    } // end for
    vector<int> a(m, 0);
    for (int i = 0; i < m; ++i) {
      cin >> a[i];
    } // end for

    int res = 0;
    int curr = 0;
    for (int i = 0; i < m; ++i) {
      //			int sign = (a[i] > 0 ? 1 : -1 );
      //			int offset = (sign == 1 ? 0 : -1 );
      int sum =
          (a[i] > 0 ? accumulate(d.begin() + curr, d.begin() + curr + a[i], 0)
                    : accumulate(d.begin() + curr + a[i], d.begin() + curr, 0));
      res = (res + sum) % M;
      curr += a[i];
    } // end for
    cout << res << endl;
  } // end loop

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm> // require sort next_permutation count etc.
#include <cctype>    // require tolower, toupper
#include <cfloat>
#include <climits> // require INT_MAX etc
#include <cmath>   // require sqrt ceil floor
#include <cstdio>  // require printf
#include <cstdlib> // require abs
#include <cstring> // require memset
#include <deque>
#include <fstream> // require freopen
#include <functional>
#include <iomanip> // require setw
#include <iostream>
#include <limits>
#include <map>
#include <numeric> // require accumulate
#include <queue>
#include <set>
#include <sstream> // require stringstream
#include <stack>
#include <stdint.h> // require uint64_t
#include <string>
#include <vector>

using namespace std;

const int M = 100000;

int main() {
  //	cut here before submit
  //	freopen ("testcase.traveler", "r", stdin );
  int n, m;

  while (cin >> n >> m && n && m) {
    vector<int> d(n, 0);
    for (int i = 0; i < n - 1; ++i) {
      cin >> d[i];
    } // end for
    vector<int> a(m, 0);
    for (int i = 0; i < m; ++i) {
      cin >> a[i];
    } // end for

    int res = 0;
    int curr = 0;
    for (int i = 0; i < m; ++i) {
      int sign = (a[i] > 0 ? 1 : -1);
      int offset = (sign == 1 ? 0 : -1);
      for (int j = 0; j < sign * a[i]; ++j) {
        res = (res + d[curr + offset]) % M;
        curr += sign;
      } // end if
    }   // end for
    cout << res << endl;
  } // end loop

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

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>

int main() {
  int town[1000000] = {0};
  int n, m;
  int ans = 0;
  int now = 0;
  scanf("%d%d", &n, &m);
  town[0] = 0;
  for (int i = 1; i < n; i++) {
    scanf("%d", &town[i]);
  }

  /*
  for(int i = 0; i < n; i++)
    printf("town%d:%d\\n", i, town[i]);
  */

  for (int i = 0; i < m; i++) {
    int h;
    scanf("%d", &h);
    // printf("now:%d ans:%d\\n", now, ans);

    if (h > 0) {
      for (int j = 0; j < h; j++) {
        ans += town[++now];
        // printf("mooov:%d\\n", town[now]);
      }
    } else {
      for (int j = 0; j < -h; j++) {
        ans += town[now--];
        // printf("mooov:%d\\n", town[now]);
      }
    }

    ans %= 100000;
  }
  printf("%d\\n", ans);
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>

int main() {
  int town[100] = {0};
  int n, m;
  int ans = 0;
  int now = 0;
  scanf("%d%d", &n, &m);
  town[0] = 0;
  for (int i = 1; i < n; i++) {
    scanf("%d", &town[i]);
  }

  /*
  for(int i = 0; i < n; i++)
    printf("town%d:%d\\n", i, town[i]);
  */

  for (int i = 0; i < m; i++) {
    int h;
    scanf("%d", &h);
    // printf("now:%d ans:%d\\n", now, ans);

    if (h > 0) {
      for (int j = 0; j < h; j++) {
        ans += town[++now];
        // printf("mooov:%d\\n", town[now]);
      }
    } else {
      for (int j = 0; j < -h; j++) {
        ans += town[now--];
        // printf("mooov:%d\\n", town[now]);
      }
    }

    ans %= 100000;
  }
  printf("%d\\n", ans);
}
Problem p00472 (C++) — buggy submission, verdict: Runtime Error

// 57
#include <cstdlib>
#include <iostream>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  int d[100000] = {};
  for (int i = 1; i < n; i++) {
    cin >> d[i];
    d[i] += d[i - 1];
  }
  int p = 0;
  int s = 0;
  while (m--) {
    int a;
    cin >> a;
    s = (s + abs(d[p] - d[p + a])) % 100000;
    p += a;
  }
  cout << s << endl;
  return 0;
}

Error: 0

Fixed submission:

// 57
#include <cstdlib>
#include <iostream>

using namespace std;

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

#include <algorithm>
#include <cstdio>
#define MOD 100000
using namespace std;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int yado[n];
  yado[0] = 0;
  scanf("%d", &yado[1]);
  for (int i = 2; i < n; i++) {
    scanf("%d", &yado[i]);
    yado[i] += yado[i - 1];
  }
  int npos = 0, in, res = 0;
  for (int i = 0; i < m; i++) {
    scanf("%d", &in);
    int s = npos, e = npos + in;
    npos = e;
    if (s > e)
      swap(s, e);
    // printf("%d %d\\n",s,e);
    res += yado[e] - yado[s];
    res %= MOD;
  }
  printf("%d\\n", res);
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <vector>
#define MOD 100000
using namespace std;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int yado[n - 1];
  // vector<int> dist[n-1];
  for (int i = 0; i < n - 1; i++)
    scanf("%d", &yado[i]);
  /*for (int i=0; i<n-1; i++) {
      dist[i].push_back(yado[i]);
      int pos=0;
      for (int j=i+1; j<n-1; j++) {
          dist[i].push_back(dist[i][pos++]+yado[j]);
      }
  }
  for (int i=0; i<n-1; i++) {
      for (int j=0; j<dist[i].size(); j++) {
          printf("%d ",dist[i][j]);
      }
      puts("");
  }*/
  int npos = 0, in, res = 0;
  for (int i = 0; i < m; i++) {
    scanf("%d", &in);
    int s = npos, e = npos + in;
    npos = e;
    if (s > e)
      swap(s, e);
    // printf("%d %d\\n",s,e);
    // res += dist[s][e-s-1];
    for (int j = s; j < e; j++) {
      res += yado[j];
      res %= MOD;
    }
  }
  printf("%d\\n", res);
}
Problem p00472 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n, m;
  for (; cin >> n >> m;) {
    long long int map[n + 2];
    long long int sum = 0;
    map[1] = 0;
    for (int i = 2; i <= n; i++) {
      int tmp;
      cin >> tmp;
      sum += tmp;
      map[i] = sum;
      //	  cout<<"map["<<i<<"]="<<map[i]<<endl;
    }
    long long int ans = 0;
    int now = 1;
    for (int i = 1; i <= m; i++) {
      int tmp;
      cin >> tmp;
      int old = now;
      now += tmp;
      ans += abs(map[now] - map[old]);
    }
    cout << ans % 100000 << endl;
  }
}

Error: TLE

Fixed submission:

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

int main() {
  int n, m;
  for (; cin >> n >> m, n;) {
    long long int map[n + 2];
    long long int sum = 0;
    map[1] = 0;
    for (int i = 2; i <= n; i++) {
      int tmp;
      cin >> tmp;
      sum += tmp;
      map[i] = sum;
      //	  cout<<"map["<<i<<"]="<<map[i]<<endl;
    }
    long long int ans = 0;
    int now = 1;
    for (int i = 1; i <= m; i++) {
      int tmp;
      cin >> tmp;
      int old = now;
      now += tmp;
      ans += abs(map[now] - map[old]);
    }
    cout << ans % 100000 << endl;
  }
}
Problem p00472 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

const int MAX_N = 1 << 18,
          MOD = 100000; // ちょっと多いけど気にしないし(少なかったし)
class SegmentTree {
public:
  SegmentTree(int _n) {
    n = 1;
    while (n < _n)
      n *= 2;
    std::fill(data, data + MAX_N, 0);
  }

  void update(int k, int i) {
    k += n - 1;
    data[k] = i;
    while (k > 0) {
      k = (k - 1) / 2;
      data[k] = (data[k * 2 + 1] + data[k * 2 + 2]) % MOD;
    }
  }

  int query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l)
      return 0;

    if (a <= l && r <= b)
      return data[k];
    else {
      int cl = query(a, b, k * 2 + 1, l, (l + r) / 2),
          cr = query(a, b, k * 2 + 2, (l + r) / 2, r);
      return (cl + cr) % MOD;
    }
  }

  int getN() { return n; }

private:
  int n, data[MAX_N];
};

int main() {
  int n, m;
  std::cin >> n >> m;
  SegmentTree st(--n);

  for (int i = 0; i < n; i++) {
    int d;
    std::cin >> d;
    st.update(i, d);
  }

  int from = 0, to, res = 0;
  for (int i = 0; i < m; i++) {
    int a;
    std::cin >> a;
    to = from + a;
    int lower = std::min(from, to), upper = std::max(from, to);
    res = (res + st.query(lower, upper, 0, 0, st.getN())) % MOD;
    from = to;
  }

  std::cout << res << std::endl;
}

Error: 0

Fixed submission:

#include <iostream>

const int MAX_N = 1 << 17, MOD = 100000; // ちょっと多いけど気にしないし
class SegmentTree {
public:
  SegmentTree(int _n) {
    n = 1;
    while (n < _n)
      n *= 2;
    std::fill(data, data + MAX_N, 0);
  }

  void update(int k, int i) {
    k += n - 1;
    data[k] = i;
    while (k > 0) {
      k = (k - 1) / 2;
      data[k] = (data[k * 2 + 1] + data[k * 2 + 2]) % MOD;
    }
  }

  int query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l)
      return 0;

    if (a <= l && r <= b)
      return data[k];
    else {
      int cl = query(a, b, k * 2 + 1, l, (l + r) / 2),
          cr = query(a, b, k * 2 + 2, (l + r) / 2, r);
      return (cl + cr) % MOD;
    }
  }

  int getN() { return n; }

private:
  int n, data[MAX_N];
};

int main() {
  int n, m;
  std::cin >> n >> m;
  SegmentTree st(--n);

  for (int i = 0; i < n; i++) {
    int d;
    std::cin >> d;
    st.update(i, d);
  }

  int from = 0, to, res = 0;
  for (int i = 0; i < m; i++) {
    int a;
    std::cin >> a;
    to = from + a;
    int lower = std::min(from, to), upper = std::max(from, to);
    res = (res + st.query(lower, upper, 0, 0, st.getN())) % MOD;
    from = to;
  }

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

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

int main(void) {
  int n, m;
  cin >> n >> m;
  vector<int> distances;
  for (int i = 0; i < n - 1; i++) {
    int tmp;
    cin >> tmp;
    distances.push_back(tmp);
  }

  int move_sum = 0, pos = 0;
  for (int i = 0; i < m; i++) {
    int move;
    cin >> move;
    if (move > 0) {
      while (move--) {
        move_sum += distances[pos];
        pos++;
      }
    } else {
      move *= -1;
      while (move--) {
        pos--;
        move_sum += distances[pos];
      }
    }
    move_sum %= 100000;
  }

  cout << move_sum << endl;
  return 0;
}

Error: WA

Fixed submission:

#include <fstream>
#include <iostream>
#include <vector>
using namespace std;

int main(void) {
  int n, m;
  ifstream ifs("input.txt");
  ofstream ofs("output.txt");
  ifs >> n >> m;
  vector<int> distances;
  for (int i = 0; i < n - 1; i++) {
    int tmp;
    ifs >> tmp;
    distances.push_back(tmp);
  }

  int move_sum = 0, pos = 0;
  for (int i = 0; i < m; i++) {
    int move;
    ifs >> move;
    if (move > 0) {
      while (move--) {
        move_sum += distances[pos];
        pos++;
      }
    } else {
      move *= -1;
      while (move--) {
        pos--;
        move_sum += distances[pos];
      }
    }
  }

  move_sum %= 100000;
  ofs << move_sum << endl;
  return 0;
}
Problem p00472 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int d[n][2];
  int dis;
  d[0][0] = d[0][1] = 0;
  for (int i = 1; i < n; i++) {
    cin >> dis;
    d[i][0] = dis;
  }
  for (int i = 1; i < n; i++)
    d[i][1] = d[i - 1][1] + d[i][0];
  // for(int i=0;i<n;i++) cout << d[i][1] << ' ';
  // cout << endl;
  int ans = 0;
  int a, mema = 0;
  for (int i = 0; i < m; i++) {
    cin >> a;
    if (a > 0)
      ans += d[mema + a][1] - d[mema][1];
    else
      ans += d[mema][1] - d[mema + a][1];
    ans %= 100000;
    mema += a;
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
#define INF (1 << 30) - 1
int main() {
  int n, m;
  cin >> n >> m;
  int d[n][n];
  int ans = 0;
  int dis;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++)
      d[i][j] = INF;
  }
  for (int i = 0; i < n - 1; i++) {
    cin >> dis;
    d[i][i + 1] = dis;
    d[i + 1][i] = dis;
  }
  for (int k = 0; k < n; k++)
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
  int a, mema = 0;
  for (int i = 0; i < m; i++) {
    cin >> a;
    ans += d[mema][mema + a];
    ans %= 100000;
    mema += a;
  }
  cout << ans << endl;
}