Problem p03743 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
// #define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a) {
  os << '(' << a.first << ',' << a.second << ')';
  return os;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
  for (auto x : v)
    os << x << ' ';
  return os;
}
void debug() { cerr << '\n'; }
template <typename H, typename... T> void debug(H a, T... b) {
  cerr << a;
  if (sizeof...(b))
    cerr << ", ";
  debug(b...);
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  ll D;
  cin >> n >> D;
  vector<ll> d(n);
  rep(i, n) cin >> d[i];
  vector<ll> now(n + 1);
  now[0] = D;
  rep(i, n) { now[i + 1] = min(now[i], abs(d[i] - now[i])); }
  show(now);
  ll a = 1;
  vector<bool> ans(n);
  for (int i = n; i >= 0; i--) {
    if (a > d[i] / 2) {
      a += d[i];
    }
    if (a <= now[i - 1]) {
      ans[i - 1] = 1;
    }
  }
  int q;
  cin >> q;
  while (q--) {
    int x;
    cin >> x;
    if (ans[x - 1]) {
      puts("YES");
    } else {
      puts("NO");
    }
  }
}


Fixed submission:
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
// #define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a) {
  os << '(' << a.first << ',' << a.second << ')';
  return os;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
  for (auto x : v)
    os << x << ' ';
  return os;
}
void debug() { cerr << '\n'; }
template <typename H, typename... T> void debug(H a, T... b) {
  cerr << a;
  if (sizeof...(b))
    cerr << ", ";
  debug(b...);
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  ll D;
  cin >> n >> D;
  vector<ll> d(n);
  rep(i, n) cin >> d[i];
  vector<ll> now(n + 1);
  now[0] = D;
  rep(i, n) { now[i + 1] = min(now[i], abs(d[i] - now[i])); }
  show(now);
  ll a = 1;
  vector<bool> ans(n);
  for (int i = n; i >= 0; i--) {
    if (a > d[i] / 2) {
      a += d[i];
    }
    if (i and a <= now[i - 1]) {
      ans[i - 1] = 1;
    }
  }
  int q;
  cin >> q;
  while (q--) {
    int x;
    cin >> x;
    if (ans[x - 1]) {
      puts("YES");
    } else {
      puts("NO");
    }
  }
}