Problem p03743 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ctype.h>
#include <cwchar>
#include <cwctype>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <math.h>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <stdio.h>
#include <stdlib.h>
#include <streambuf>
#include <string.h>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
int n, d, q, a[100010], b[100010], f[100010];
int main() {
  scanf("%d%d", &n, &d);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  b[0] = d;
  for (int i = 1; i <= n; i++) {
    if (2 * b[i - 1] > a[i]) {
      b[i] = abs(a[i] - b[i - 1]);
    } else {
      b[i] = b[i - 1];
    }
  }
  f[n + 1] = 0;
  for (int i = n; i; i--) {
    if (a[i] <= 2 * f[i + 1] + 1) {
      f[i] = f[i + 1] + a[i];
    } else {
      f[i] = f[i + 1];
    }
  }
  scanf("%d", &q);
  while (q--) {
    int x;
    scanf("%d", &x);
    if (b[x - 1] > f[x + 1]) {
      puts("YES");
    } else {
      puts("NO");
    }
  }
  return 0;
}
// 形之美，人人可见，心之美，非眼能看到，我愿意独享。

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ctype.h>
#include <cwchar>
#include <cwctype>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <math.h>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <stdio.h>
#include <stdlib.h>
#include <streambuf>
#include <string.h>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
int n, d, q, a[500010], b[500010], f[500010];
int main() {
  scanf("%d%d", &n, &d);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  b[0] = d;
  for (int i = 1; i <= n; i++) {
    if (2 * b[i - 1] > a[i]) {
      b[i] = abs(a[i] - b[i - 1]);
    } else {
      b[i] = b[i - 1];
    }
  }
  f[n + 1] = 0;
  for (int i = n; i; i--) {
    if (a[i] <= 2 * f[i + 1] + 1) {
      f[i] = f[i + 1] + a[i];
    } else {
      f[i] = f[i + 1];
    }
  }
  scanf("%d", &q);
  while (q--) {
    int x;
    scanf("%d", &x);
    if (b[x - 1] > f[x + 1]) {
      puts("YES");
    } else {
      puts("NO");
    }
  }
  return 0;
}
// 形之美，人人可见，心之美，非眼能看到，我愿意独享。