Problem p03743 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <vector>

#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
#define LL long long
#define INF (2147483647)
#define sqr(x) ((x) * (x))

using namespace std;

inline void read(int &data) {
  data = 0;
  int w = 1;
  char ch = 0;
  while (ch != '-' && (ch < '0' || ch > '9'))
    ch = getchar();
  if (ch == '-')
    w = -1, ch = getchar();
  while (ch >= '0' && ch <= '9')
    data = data * 10 + ch - '0', ch = getchar();
  data = data * w;
}

inline void write(int x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    write(x / 10);
  putchar(x % 10 + '0');
}

inline void read(LL &data) {
  data = 0;
  int w = 1;
  char ch = 0;
  while (ch != '-' && (ch < '0' || ch > '9'))
    ch = getchar();
  if (ch == '-')
    w = -1, ch = getchar();
  while (ch >= '0' && ch <= '9')
    data = data * 10 + ch - '0', ch = getchar();
  data = data * w;
}

inline void write(LL x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    write(x / 10);
  putchar(x % 10 + '0');
}

int d[100005], b[100005], t[100005], a[100005];

int main() {
  int n, dis;
  read(n), read(dis);
  rep(i, 1, n) {
    read(d[i]);
    a[i] = dis;
    dis = min(dis, abs(dis - d[i]));
  }
  int q;
  read(q);
  rep(i, 1, q) read(t[i]);
  b[n + 1] = 1;
  per(i, n, 1) if (b[i + 1] <= d[i] / 2) b[i] = b[i + 1];
  else b[i] = b[i + 1] + d[i];
  rep(i, 1, q) if (b[t[i] + 1] <= a[t[i]]) puts("YES");
  else puts("NO");
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <vector>

#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
#define LL long long
#define INF (2147483647)
#define sqr(x) ((x) * (x))

using namespace std;

inline void read(int &data) {
  data = 0;
  int w = 1;
  char ch = 0;
  while (ch != '-' && (ch < '0' || ch > '9'))
    ch = getchar();
  if (ch == '-')
    w = -1, ch = getchar();
  while (ch >= '0' && ch <= '9')
    data = data * 10 + ch - '0', ch = getchar();
  data = data * w;
}

inline void write(int x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    write(x / 10);
  putchar(x % 10 + '0');
}

inline void read(LL &data) {
  data = 0;
  int w = 1;
  char ch = 0;
  while (ch != '-' && (ch < '0' || ch > '9'))
    ch = getchar();
  if (ch == '-')
    w = -1, ch = getchar();
  while (ch >= '0' && ch <= '9')
    data = data * 10 + ch - '0', ch = getchar();
  data = data * w;
}

inline void write(LL x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    write(x / 10);
  putchar(x % 10 + '0');
}

int d[1000005], b[1000005], t[1000005], a[1000005];

int main() {
  int n, dis;
  read(n), read(dis);
  rep(i, 1, n) {
    read(d[i]);
    a[i] = dis;
    dis = min(dis, abs(dis - d[i]));
  }
  int q;
  read(q);
  rep(i, 1, q) read(t[i]);
  b[n + 1] = 1;
  per(i, n, 1) if (b[i + 1] <= d[i] / 2) b[i] = b[i + 1];
  else b[i] = b[i + 1] + d[i];
  rep(i, 1, q) if (b[t[i] + 1] <= a[t[i]]) puts("YES");
  else puts("NO");
}