prithivMLmods/Coder-Stat huggingface dataset:
Problem p03739 (C++)

Buggy submission (status: Runtime Error):
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <unordered_map>
#include <vector>
#define mod 998244353
#define int long long
#define ld long double
#define pb push_back
#define vi vector<int>
#define dbg(x) cerr << #x << " = " << x << '\n'
#define sz(x) (int)x.size()
#define ff first
#define ss second
#define pii pair<int, int>
using namespace std;

inline void solve() {
  int n;
  cin >> n;
  vi a(n);
  for (int &i : a)
    cin >> i;
  int p = 0, ne = 0, s = 0;
  for (int i = 0; i < n; i++) {
    s += a[i];
    if (i & 1) {
      if (s >= 0) {
        p += s + 1;
        s = -1;
      }
    } else {
      if (s <= 0) {
        p += abs(s) + 1;
        s = 1;
      }
    }
  }
  s = 0;
  for (int i = 0; i < n; i++) {
    s += a[i];
    if (i % 2 == 0) {
      if (s >= 0) {
        ne += s + 1;
        s = -1;
      }
    } else {
      if (s <= 0) {
        ne += abs(s) + 1;
        s = 1;
      }
    }
  }
  cout << min(p, ne) << endl;
}

signed main() {
  int n = 1;
  cin >> n;
  while (n--)
    solve();
  return 0;
}


Fixed submission:
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <unordered_map>
#include <vector>
#define mod 998244353
#define int long long
#define ld long double
#define pb push_back
#define vi vector<int>
#define dbg(x) cerr << #x << " = " << x << '\n'
#define sz(x) (int)x.size()
#define ff first
#define ss second
#define pii pair<int, int>
using namespace std;

inline void solve() {
  int n;
  cin >> n;
  vi a(n);
  for (int &i : a)
    cin >> i;
  int p = 0, ne = 0, s = 0;
  for (int i = 0; i < n; i++) {
    s += a[i];
    if (i & 1) {
      if (s >= 0) {
        p += s + 1;
        s = -1;
      }
    } else {
      if (s <= 0) {
        p += abs(s) + 1;
        s = 1;
      }
    }
  }
  s = 0;
  for (int i = 0; i < n; i++) {
    s += a[i];
    if (i % 2 == 0) {
      if (s >= 0) {
        ne += s + 1;
        s = -1;
      }
    } else {
      if (s <= 0) {
        ne += abs(s) + 1;
        s = 1;
      }
    }
  }
  cout << min(p, ne) << endl;
}

signed main() {
  int n = 1; // cin>>n;
  while (n--)
    solve();
  return 0;
}
Problem p03740 (Python)

Buggy submission (status: Runtime Error):
x, y = input().split()
print("Alice") if (x + y) > 1 else print("Brown")


Fixed submission:
x, y = map(int, input().split())
print("Alice") if abs(x - y) > 1 else print("Brown")
Problem p03740 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;
#define rep(i, n) for (int i = 0; i < (n); ++i)

int main() {
  ll x, y;
  cin >> x >> y;

  bool alice_turn = true;

  while (1) {
    if (x < 2 && y < 2)
      break;
    if (y > x) {
      swap(x, y);
    }
    x += y / 2;
    y = y % 2;
    alice_turn = !alice_turn;
  }

  if (alice_turn) {
    cout << "Brown" << endl;
  } else {
    cout << "Alice" << endl;
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;
#define rep(i, n) for (int i = 0; i < (n); ++i)

int main() {
  ll x, y;
  cin >> x >> y;

  if (abs(x - y) <= 1) {
    cout << "Brown" << endl;
  } else {
    cout << "Alice" << endl;
  }

  return 0;
}
Problem p03741 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long a[1000000000];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long w = 0, sum = 0;
  for (int i = 0; i < n; i++) {
    sum += a[i];
    if (i % 2 == 0) {
      if (sum <= 0)
        w += 1 - sum, sum = 1;
    } else {
      if (sum >= 0)
        w += sum + 1, sum = -1;
    }
  }
  long long ans = w;
  w = 0;
  sum = 0;
  for (int i = 0; i < n; i++) {
    sum += a[i];
    if (i % 2 == 1) {
      if (sum <= 0)
        w += 1 - sum, sum = 1;
    } else {
      if (sum >= 0)
        w += sum + 1, sum = -1;
    }
  }
  ans = min(ans, w);
  cout << ans;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long a[100000];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long w = 0, sum = 0;
  for (int i = 0; i < n; i++) {
    sum += a[i];
    if (i % 2 == 0) {
      if (sum <= 0)
        w += 1 - sum, sum = 1;
    } else {
      if (sum >= 0)
        w += sum + 1, sum = -1;
    }
  }
  long long ans = w;
  w = 0;
  sum = 0;
  for (int i = 0; i < n; i++) {
    sum += a[i];
    if (i % 2 == 1) {
      if (sum <= 0)
        w += 1 - sum, sum = 1;
    } else {
      if (sum >= 0)
        w += sum + 1, sum = -1;
    }
  }
  ans = min(ans, w);
  cout << ans;
  return 0;
}
Problem p03741 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define pi pair<ll, ll>
#define pii pair<ll, pi>
#define pb push_back
#define mk make_pair
ll issign(ll x) { return (x > 0) - (x < 0); }
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll ans = 1e18;
  for (int possible = -1; possible <= 1; possible += 2) {
    ll sum = 0;
    ll cost = 0;
    for (int i = 0; i < n; i++) {
      sum += a[i];
      ll have;
      if (i & 1)
        have = -possible;
      else
        have = possible;
      if (issign(sum) != have) {
        cost += abs(sum - have);
        sum = have;
      }
    }
    ans = min(ans, cost);
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define pi pair<ll, ll>
#define pii pair<ll, pi>
#define pb push_back
#define mk make_pair
ll issign(ll x) { return (x > 0) - (x < 0); }
int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll ans = 1e18;
  for (int possible = -1; possible <= 1; possible += 2) {
    ll sum = 0;
    ll cost = 0;
    for (int i = 0; i < n; i++) {
      sum += a[i];
      ll have;
      if (i & 1)
        have = -possible;
      else
        have = possible;
      if (issign(sum) != have) {
        cost += abs(sum - have);
        sum = have;
      }
    }
    ans = min(ans, cost);
  }
  cout << ans << endl;
}
Problem p03742 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i, a, b) for (register sign i = (sign)(a); i <= (sign)(b); ++i)
#define Fordown(i, a, b) for (register sign i = (sign)(a); i >= (sign)(b); --i)
const int N = 100 + 5;
template <typename T> bool cmax(T &a, T b) { return (a < b) ? a = b, 1 : 0; }
template <typename T> bool cmin(T &a, T b) { return (a > b) ? a = b, 1 : 0; }
template <typename T> T read() {
  T ans = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch) && ch != '-')
    ch = getchar();
  if (ch == '-')
    f = -1, ch = getchar();
  while (isdigit(ch))
    ans = (ans << 3) + (ans << 1) + (ch - '0'), ch = getchar();
  return ans * f;
}
template <typename T> void write(T x, char y) {
  if (x == 0) {
    putchar('0'), putchar(y);
    return;
  }
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  static char wr[20];
  int top = 0;
  for (; x; x /= 10)
    wr[++top] = x % 10 + '0';
  while (top)
    putchar(wr[top--]);
  putchar(y);
}
void file() {
#ifndef ONLINE_JUDGE
  freopen("D.in", "r", stdin);
  freopen("D.out", "w", stdout);
#endif
}
ll x, y;
void input() { x = read<ll>(), y = read<ll>(); }
void work() {
  if (abs(x - y) > 1)
    puts("Alice");
  else
    puts("Brown");
}
int main() {
  file();
  input();
  work();
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i, a, b) for (register sign i = (sign)(a); i <= (sign)(b); ++i)
#define Fordown(i, a, b) for (register sign i = (sign)(a); i >= (sign)(b); --i)
const int N = 100 + 5;
template <typename T> bool cmax(T &a, T b) { return (a < b) ? a = b, 1 : 0; }
template <typename T> bool cmin(T &a, T b) { return (a > b) ? a = b, 1 : 0; }
template <typename T> T read() {
  T ans = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch) && ch != '-')
    ch = getchar();
  if (ch == '-')
    f = -1, ch = getchar();
  while (isdigit(ch))
    ans = (ans << 3) + (ans << 1) + (ch - '0'), ch = getchar();
  return ans * f;
}
template <typename T> void write(T x, char y) {
  if (x == 0) {
    putchar('0'), putchar(y);
    return;
  }
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  static char wr[20];
  int top = 0;
  for (; x; x /= 10)
    wr[++top] = x % 10 + '0';
  while (top)
    putchar(wr[top--]);
  putchar(y);
}
void file() {
#ifndef ONLINE_JUDGE
  freopen("D.in", "r", stdin);
  freopen("D.out", "w", stdout);
#endif
}
ll x, y;
void input() { x = read<ll>(), y = read<ll>(); }
void work() {
  if (abs(x - y) > 1)
    puts("Alice");
  else
    puts("Brown");
}
int main() {
  // file();
  input();
  work();
  return 0;
}
Problem p03743 (C++)

Buggy submission (status: Runtime Error):
// Jai Shree Krishna
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define loop(i, n) for (int i = 0; i < n; i += 1)
#define loop2(i, n) for (int i = 1; i <= n; i += 1)

vector<ll> x(1e5 + 100);
vector<ll> ds(1e5 + 100);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  // equivalent to finding minimum number that can not be formed
  ll n, d;
  cin >> n >> d;
  loop(i, n) { cin >> x[i]; }
  ds[0] = d;
  loop(i, n) { ds[i + 1] = min(ds[i], abs(ds[i] - x[i])); }
  vector<bool> res(n);
  ll b = 1;
  for (ll i = n - 1; i > -1; --i) {
    res[i] = (b <= ds[i]);
    if (x[i] < 2 * b) {
      b += x[i];
    }
  }
  ll q;
  cin >> q;
  while (q--) {
    ll temp;
    cin >> temp;
    if (res[temp - 1]) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}


Fixed submission:
// Jai Shree Krishna
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define loop(i, n) for (int i = 0; i < n; i += 1)
#define loop2(i, n) for (int i = 1; i <= n; i += 1)

vector<ll> x(5e5 + 100);
vector<ll> ds(5e5 + 100);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  // equivalent to finding minimum number that can not be formed
  ll n, d;
  cin >> n >> d;
  loop(i, n) { cin >> x[i]; }
  ds[0] = d;
  loop(i, n) { ds[i + 1] = min(ds[i], abs(ds[i] - x[i])); }
  vector<bool> res(n);
  ll b = 1;
  for (ll i = n - 1; i > -1; --i) {
    res[i] = (b <= ds[i]);
    if (x[i] < 2 * b) {
      b += x[i];
    }
  }
  ll q;
  cin >> q;
  while (q--) {
    ll temp;
    cin >> temp;
    if (res[temp - 1]) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}
Problem p03743 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
const int MAX = 100005;
int n, q;
int d, a[MAX], query[MAX], dp[MAX], pos[MAX];
bool ans[MAX];
int main() {
  scanf("%d%d", &n, &d);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
  }
  scanf("%d", &q);
  for (int i = 1; i <= q; ++i) {
    scanf("%d", &query[i]);
  }
  dp[n] = 1;
  for (int i = n - 1; i >= 1; --i) {
    if (dp[i + 1] <= (a[i + 1] / 2))
      dp[i] = dp[i + 1];
    else
      dp[i] = dp[i + 1] + a[i + 1];
  }
  pos[0] = d;
  for (int i = 1; i <= n; ++i) {
    if (d > abs(d - a[i])) {
      d = abs(d - a[i]);
    }
    pos[i] = d;
  }
  for (int i = 1; i <= q; ++i) {
    if (pos[query[i] - 1] >= dp[query[i]])
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
const int MAX = 500005;
int n, q;
int d, a[MAX], query[MAX], dp[MAX], pos[MAX];
bool ans[MAX];
int main() {
  scanf("%d%d", &n, &d);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
  }
  scanf("%d", &q);
  for (int i = 1; i <= q; ++i) {
    scanf("%d", &query[i]);
  }
  dp[n] = 1;
  for (int i = n - 1; i >= 1; --i) {
    if (dp[i + 1] <= (a[i + 1] / 2))
      dp[i] = dp[i + 1];
    else
      dp[i] = dp[i + 1] + a[i + 1];
  }
  pos[0] = d;
  for (int i = 1; i <= n; ++i) {
    if (d > abs(d - a[i])) {
      d = abs(d - a[i]);
    }
    pos[i] = d;
  }
  for (int i = 1; i <= q; ++i) {
    if (pos[query[i] - 1] >= dp[query[i]])
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}
Problem p03743 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

int main() {
  ll n, d;
  cin >> n >> d;
  vector<ll> a(n), p(n), q(n + 1);
  rep(i, n) cin >> a[i];
  p[0] = d;
  for (int i = 1; i < n; i++) {
    if (abs(p[i - 1]) >= abs(p[i - 1] - a[i - 1])) {
      p[i] = abs(p[i - 1] - a[i - 1]);
    } else {
      p[i] = p[i - 1];
    }
  }
  ll c = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (a[i] <= 2 * c + 1) {
      c += a[i];
    }
    q[i] = c;
  }
  rep(i, n) { cerr << p[i] << " " << q[i + 1] << endl; }
  vector<bool> flag(n);
  rep(i, n) {
    if (p[i] <= q[i + 1]) {
      flag[i] = true;
    }
  }
  int qq;
  cin >> qq;
  rep(tt, qq) {
    int x;
    cin >> x;
    x--;
    if (flag[x]) {
      cout << "NO" << endl;
    } else {
      cout << "YES" << endl;
    }
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

int main() {
  ll n, d;
  cin >> n >> d;
  vector<ll> a(n), p(n), q(n + 1);
  rep(i, n) cin >> a[i];
  p[0] = d;
  for (int i = 1; i < n; i++) {
    if (abs(p[i - 1]) >= abs(p[i - 1] - a[i - 1])) {
      p[i] = abs(p[i - 1] - a[i - 1]);
    } else {
      p[i] = p[i - 1];
    }
  }
  ll c = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (a[i] <= 2 * c + 1) {
      c += a[i];
    }
    q[i] = c;
  }
  // rep(i,n){
  // 	cerr << p[i] << " " << q[i+1] << endl;
  // }
  vector<bool> flag(n);
  rep(i, n) {
    if (p[i] <= q[i + 1]) {
      flag[i] = true;
    }
  }
  int qq;
  cin >> qq;
  rep(tt, qq) {
    int x;
    cin >> x;
    x--;
    if (flag[x]) {
      cout << "NO" << endl;
    } else {
      cout << "YES" << endl;
    }
  }
  return 0;
}
Problem p03743 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
using namespace std;
const int N = 1e5 + 5;
int n, m, i, a[N], d[N];
long long mn;
bool ans[N];
int read() {
  char c = getchar();
  int k = 0;
  for (; c < 48 || c > 57; c = getchar())
    ;
  for (; c > 47 && c < 58; c = getchar())
    k = (k << 3) + (k << 1) + c - 48;
  return k;
}
int main() {
  for (n = read(), d[0] = read(), i = 1; i <= n; i++)
    d[i] = min(d[i - 1], abs(d[i - 1] - (a[i] = read())));
  for (mn = 1, i = n; i; i--) {
    if (d[i - 1] >= mn)
      ans[i] = 1;
    if (2 * mn > a[i])
      mn = mn + a[i];
  }
  for (i = read(); i--;)
    puts(ans[read()] ? "YES" : "NO");
}

Fixed submission:
#include <algorithm>
#include <cstdio>
using namespace std;
const int N = 5e5 + 5;
int n, m, i, a[N], d[N];
long long mn;
bool ans[N];
int read() {
  char c = getchar();
  int k = 0;
  for (; c < 48 || c > 57; c = getchar())
    ;
  for (; c > 47 && c < 58; c = getchar())
    k = (k << 3) + (k << 1) + c - 48;
  return k;
}
int main() {
  for (n = read(), d[0] = read(), i = 1; i <= n; i++)
    d[i] = min(d[i - 1], abs(d[i - 1] - (a[i] = read())));
  for (mn = 1, i = n; i; i--) {
    if (d[i - 1] >= mn)
      ans[i] = 1;
    if (2 * mn > a[i])
      mn = mn + a[i];
  }
  for (i = read(); i--;)
    puts(ans[read()] ? "YES" : "NO");
}
Problem p03743 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sqr(x) ((x) * (x))
#define mp make_pair
#define uint unsigned
#define PI pair<int, int>
inline char gc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
#define gc getchar
inline int read() {
  int x = 0;
  char ch = gc();
  bool positive = 1;
  for (; !isdigit(ch); ch = gc())
    if (ch == '-')
      positive = 0;
  for (; isdigit(ch); ch = gc())
    x = x * 10 + ch - '0';
  return positive ? x : -x;
}
inline void write(int a) {
  if (a < 0) {
    a = -a;
    putchar('-');
  }
  if (a >= 10)
    write(a / 10);
  putchar('0' + a % 10);
}
inline void writeln(int a) {
  if (a < 0) {
    a = -a;
    putchar('-');
  }
  write(a);
  puts("");
}
inline int rnd(int x) { return (rand() << 16 | rand()) % x; }
const int N = 100005;
int n, f[N], g[N], d[N], q;
int main() {
  n = read();
  f[0] = read();
  for (int i = 1; i <= n; i++)
    d[i] = read();
  q = read();
  for (int i = 1; i <= n; i++) {
    f[i] = min(f[i - 1], abs(f[i - 1] - d[i]));
  }
  g[n + 1] = 1;
  for (int i = n; i; i--)
    g[i] = d[i] < 2 * g[i + 1] ? d[i] + g[i + 1] : g[i + 1];
  for (int i = 1; i <= q; i++) {
    int x = read();
    if (g[x + 1] <= f[x - 1])
      puts("YES");
    else
      puts("NO");
  }
}
/*

*/

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sqr(x) ((x) * (x))
#define mp make_pair
#define uint unsigned
#define PI pair<int, int>
inline char gc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
#define gc getchar
inline int read() {
  int x = 0;
  char ch = gc();
  bool positive = 1;
  for (; !isdigit(ch); ch = gc())
    if (ch == '-')
      positive = 0;
  for (; isdigit(ch); ch = gc())
    x = x * 10 + ch - '0';
  return positive ? x : -x;
}
inline void write(int a) {
  if (a < 0) {
    a = -a;
    putchar('-');
  }
  if (a >= 10)
    write(a / 10);
  putchar('0' + a % 10);
}
inline void writeln(int a) {
  if (a < 0) {
    a = -a;
    putchar('-');
  }
  write(a);
  puts("");
}
inline int rnd(int x) { return (rand() << 16 | rand()) % x; }
const int N = 500005;
int n, f[N], g[N], d[N], q;
int main() {
  n = read();
  f[0] = read();
  for (int i = 1; i <= n; i++)
    d[i] = read();
  q = read();
  for (int i = 1; i <= n; i++) {
    f[i] = min(f[i - 1], abs(f[i - 1] - d[i]));
  }
  g[n + 1] = 1;
  for (int i = n; i; i--)
    g[i] = d[i] < 2 * g[i + 1] ? d[i] + g[i + 1] : g[i + 1];
  for (int i = 1; i <= q; i++) {
    int x = read();
    if (g[x + 1] <= f[x - 1])
      puts("YES");
    else
      puts("NO");
  }
}
/*

*/
Problem p03743 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>

#define Rep(i, n) for (int i = 1; i <= n; i++)
#define Rep0(i, n) for (int i = 0; i <= n; i++)
#define RepG(i, x) for (int i = head[x]; i; i = edge[i].next)
#define v edge[i].to

using namespace std;

const int N = 100010;

int dis[N], d[N], f[N];

int main() {
  int n, q, D;
  scanf("%d%d", &n, &D);
  dis[0] = D;
  Rep(i, n) {
    scanf("%d", &d[i]);
    dis[i] = min(dis[i - 1], abs(dis[i - 1] - d[i]));
  }
  f[n + 1] = 0;
  for (int i = n; i; i--) {
    if (d[i] < (f[i + 1] + 1) * 2)
      f[i] = f[i + 1] + d[i];
    else
      f[i] = f[i + 1];
  }
  scanf("%d", &q);
  Rep(i, q) {
    int x;
    scanf("%d", &x);
    if (dis[x - 1] > f[x + 1])
      printf("YES\n");
    else
      printf("NO\n");
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>

#define Rep(i, n) for (int i = 1; i <= n; i++)
#define Rep0(i, n) for (int i = 0; i <= n; i++)
#define RepG(i, x) for (int i = head[x]; i; i = edge[i].next)
#define v edge[i].to

using namespace std;

const int N = 500010;

int dis[N], d[N], f[N];

int main() {
  int n, q, D;
  scanf("%d%d", &n, &D);
  dis[0] = D;
  Rep(i, n) {
    scanf("%d", &d[i]);
    dis[i] = min(dis[i - 1], abs(dis[i - 1] - d[i]));
  }
  f[n + 1] = 0;
  for (int i = n; i; i--) {
    if (d[i] < (f[i + 1] + 1) * 2)
      f[i] = f[i + 1] + d[i];
    else
      f[i] = f[i + 1];
  }
  scanf("%d", &q);
  Rep(i, q) {
    int x;
    scanf("%d", &x);
    if (dis[x - 1] > f[x + 1])
      printf("YES\n");
    else
      printf("NO\n");
  }

  return 0;
}
Problem p03743 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
const int N = 1e5 + 7;
int n, q, as[N], L[N], R[N];
int main() {
  scanf("%d%d", &n, L);
  R[n + 1] = 1;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", as + i);
    L[i] = std::min(L[i - 1], std::abs(L[i - 1] - as[i]));
  }
  for (int i = n; i; --i)
    R[i] = R[i + 1] + (R[i + 1] <= as[i] / 2 ? 0 : as[i]);
  scanf("%d", &q);
  for (int i = 1, x; i <= q; ++i) {
    scanf("%d", &x);
    puts(L[x - 1] >= R[x + 1] ? "YES" : "NO");
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
const int N = 5e5 + 7;
int n, q, as[N], L[N], R[N];
int main() {
  scanf("%d%d", &n, L);
  R[n + 1] = 1;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", as + i);
    L[i] = std::min(L[i - 1], std::abs(L[i - 1] - as[i]));
  }
  for (int i = n; i; --i)
    R[i] = R[i + 1] + (R[i + 1] <= as[i] / 2 ? 0 : as[i]);
  scanf("%d", &q);
  for (int i = 1, x; i <= q; ++i) {
    scanf("%d", &x);
    puts(L[x - 1] >= R[x + 1] ? "YES" : "NO");
  }
  return 0;
}
Problem p03743 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int N, Q, D;
int d[100010];
int can[100010];
int im[100010];

int main() {
  scanf("%d%d", &N, &D);
  for (int i = 0; i < N; i++)
    scanf("%d", &d[i]);
  can[0] = D;
  for (int i = 1; i < N; i++)
    can[i] = min(can[i - 1], abs(can[i - 1] - d[i - 1]));
  d[N] = 0;
  im[N] = 1;
  for (int i = N - 1; i >= 0; i--) {
    if (abs(im[i + 1] - d[i + 1]) < im[i + 1])
      im[i] = im[i + 1] + d[i + 1];
    else
      im[i] = im[i + 1];
  }
  scanf("%d", &Q);
  for (int i = 0; i < Q; i++) {
    int q;
    scanf("%d", &q);
    if (can[q - 1] >= im[q - 1])
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int N, Q, D;
int d[500010];
int can[500010];
int im[500010];

int main() {
  scanf("%d%d", &N, &D);
  for (int i = 0; i < N; i++)
    scanf("%d", &d[i]);
  can[0] = D;
  for (int i = 1; i < N; i++)
    can[i] = min(can[i - 1], abs(can[i - 1] - d[i - 1]));
  d[N] = 0;
  im[N] = 1;
  for (int i = N - 1; i >= 0; i--) {
    if (abs(im[i + 1] - d[i + 1]) < im[i + 1])
      im[i] = im[i + 1] + d[i + 1];
    else
      im[i] = im[i + 1];
  }
  scanf("%d", &Q);
  for (int i = 0; i < Q; i++) {
    int q;
    scanf("%d", &q);
    if (can[q - 1] >= im[q - 1])
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}
Problem p03743 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x, to) for (x = 0; x < (to); x++)
#define FORR(x, arr) for (auto &x : arr)
#define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
//-------------------------------------------------------

int N, D;
ll Q;
ll X[505050];
ll L[505050];
int QQ[505050];
ll NG[101010];

void solve() {
  int i, j, k, l, r, x, y;
  string s;

  cin >> N >> D;
  L[0] = D;
  FOR(i, N) {
    cin >> X[i];
    L[i + 1] = min(L[i], abs(L[i] - X[i]));
  }

  cin >> Q;
  FOR(i, Q) cin >> QQ[i];

  if (L[N] > 0) {
    FOR(i, Q) cout << "YES" << endl;
  } else {
    NG[N] = 1;
    for (i = N - 1; i >= 0; i--) {
      if (NG[i + 1] <= X[i] / 2)
        NG[i] = NG[i + 1];
      else
        NG[i] = NG[i + 1] + X[i];
    }

    FOR(i, Q) {
      x = QQ[i];
      if (L[x - 1] == 0 || NG[x] > L[x - 1])
        cout << "NO" << endl;
      else
        cout << "YES" << endl;
    }
  }
}

int main(int argc, char **argv) {
  string s;
  int i;
  if (argc == 1)
    ios::sync_with_stdio(false), cin.tie(0);
  FOR(i, argc - 1) s += argv[i + 1], s += '\n';
  FOR(i, s.size()) ungetc(s[s.size() - 1 - i], stdin);
  solve();
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x, to) for (x = 0; x < (to); x++)
#define FORR(x, arr) for (auto &x : arr)
#define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
//-------------------------------------------------------

int N, D;
ll Q;
ll X[505050];
ll L[505050];
int QQ[505050];
ll NG[501010];

void solve() {
  int i, j, k, l, r, x, y;
  string s;

  cin >> N >> D;
  L[0] = D;
  FOR(i, N) {
    cin >> X[i];
    L[i + 1] = min(L[i], abs(L[i] - X[i]));
  }

  cin >> Q;
  FOR(i, Q) cin >> QQ[i];

  if (L[N] > 0) {
    FOR(i, Q) cout << "YES" << endl;
  } else {
    NG[N] = 1;
    for (i = N - 1; i >= 0; i--) {
      if (NG[i + 1] <= X[i] / 2)
        NG[i] = NG[i + 1];
      else
        NG[i] = NG[i + 1] + X[i];
    }

    FOR(i, Q) {
      x = QQ[i];
      if (L[x - 1] == 0 || NG[x] > L[x - 1])
        cout << "NO" << endl;
      else
        cout << "YES" << endl;
    }
  }
}

int main(int argc, char **argv) {
  string s;
  int i;
  if (argc == 1)
    ios::sync_with_stdio(false), cin.tie(0);
  FOR(i, argc - 1) s += argv[i + 1], s += '\n';
  FOR(i, s.size()) ungetc(s[s.size() - 1 - i], stdin);
  solve();
  return 0;
}
Problem p03743 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#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--)
using namespace std;
typedef long long LL;

inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!(ch >= '0' && ch <= '9')) {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + (ch - '0');
    ch = getchar();
  }
  return x * f;
}

const int N = 500010;

int n, q, D, d[N], A[N], B[N],
    ans[N]; // What we ONLY need to judge is just a bounder -> B[i] the minimum
            // dis if we don't want to reach the goal

int main() {

#ifndef ONLINE_JUDGE
  freopen("data.in", "r", stdin);
  freopen("data.out", "w", stdout);
#endif

  n = read(), D = read();
  A[0] = D;
  rep(i, 1, n) d[i] = read();
  int dis = D;
  rep(i, 1, n) A[i] = dis = min(dis, abs(dis - d[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];
    if (A[i - 1] >= B[i + 1])
      ans[i] = 1;
    else
      ans[i] = 0;
  }
  int Q = read();
  while (Q--) {
    int x = read();
    if (ans[x])
      puts("YES");
    else
      puts("NO");
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#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--)
using namespace std;
typedef long long LL;

inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!(ch >= '0' && ch <= '9')) {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + (ch - '0');
    ch = getchar();
  }
  return x * f;
}

const int N = 500010;

int n, q, D, d[N], A[N], B[N],
    ans[N]; // What we ONLY need to judge is just a bounder -> B[i] the minimum
            // dis if we don't want to reach the goal

int main() {

#ifndef ONLINE_JUDGE
//	freopen("data.in","r",stdin);
//	freopen("data.out","w",stdout);
#endif

  n = read(), D = read();
  A[0] = D;
  rep(i, 1, n) d[i] = read();
  int dis = D;
  rep(i, 1, n) A[i] = dis = min(dis, abs(dis - d[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];
    if (A[i - 1] >= B[i + 1])
      ans[i] = 1;
    else
      ans[i] = 0;
  }
  int Q = read();
  while (Q--) {
    int x = read();
    if (ans[x])
      puts("YES");
    else
      puts("NO");
  }

  return 0;
}
Problem p03743 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define int long long
using namespace std;

int n, d, q, a[500000], x[500010], y[500010] = {};

bool C(int i, int z) {
  for (; i < n; i++) {
    if (a[i] / 2 <= z)
      z = max(a[i] / 2, z - a[i]);
  }
  return !z;
}

signed main() {
  scanf("%lld %lld", &n, &d);
  for (int i = 0; i < n; i++)
    scanf("%lld", &a[i]);
  x[0] = d;
  for (int i = 0; i < n; i++) {
    if (x[i] > a[i])
      x[i + 1] = x[i] - a[i];
    else
      x[i + 1] = min(x[i], a[i] - x[i]);
  }
  bool flag = false;
  for (int i = n - 1; i >= 0; i--) {
    if (flag) {
      if (y[i + 1] < a[i] / 2)
        y[i] = y[i + 1];
      else
        y[i] = y[i + 1] + a[i];
    }
    if (a[i] == 1) {
      int low = 0, up = d + 1;
      while (up - low > 1) {
        int mid = (low + up) / 2;
        if (C(i, mid))
          low = mid;
        else
          up = mid;
      }
      y[i] = low;
      flag = true;
    }
  }
  scanf("%lld", &q);
  for (int i = 0; i < q; i++) {
    int t;
    scanf("%lld", &t);
    t--;
    if (x[t] <= y[t + 1])
      cout << "NO" << endl;
    else
      cout << "YES" << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define int long long
using namespace std;

int n, d, q, a[500000], x[500010], y[500010] = {};

bool C(int i, int z) {
  for (; i < n; i++) {
    if (a[i] / 2 <= z)
      z = max(a[i] / 2, z - a[i]);
  }
  return !z;
}

signed main() {
  scanf("%lld %lld", &n, &d);
  for (int i = 0; i < n; i++)
    scanf("%lld", &a[i]);
  x[0] = d;
  for (int i = 0; i < n; i++) {
    if (x[i] > a[i])
      x[i + 1] = x[i] - a[i];
    else
      x[i + 1] = min(x[i], a[i] - x[i]);
  }
  bool flag = false;
  for (int i = n - 1; i >= 0; i--) {
    if (flag) {
      if (y[i + 1] < a[i] / 2)
        y[i] = y[i + 1];
      else
        y[i] = y[i + 1] + a[i];
    }
    if (a[i] == 1 && !flag) {
      int low = 0, up = d + 1;
      while (up - low > 1) {
        int mid = (low + up) / 2;
        if (C(i, mid))
          low = mid;
        else
          up = mid;
      }
      y[i] = low;
      flag = true;
    }
  }
  scanf("%lld", &q);
  for (int i = 0; i < q; i++) {
    int t;
    scanf("%lld", &t);
    t--;
    if (x[t] <= y[t + 1])
      cout << "NO" << endl;
    else
      cout << "YES" << endl;
  }
  return 0;
}
Problem p03743 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 7;

int a[N];
int dis[N];
int req[N];

int main() {
  ios::sync_with_stdio(false);

  int n;
  cin >> n >> dis[0];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++)
    dis[i + 1] = min(abs(dis[i] - a[i]), dis[i]);
  req[n] = 1;
  for (int i = n - 1; i >= 0; i--) {
    req[i] = req[i + 1];
    if (abs(req[i] - a[i]) < req[i])
      req[i] += a[i];
  }
  int q;
  cin >> q;
  while (q--) {
    int x;
    cin >> x;
    x--;
    if (dis[x] >= req[x + 1])
      cout << "YES\n";
    else
      cout << "NO\n";
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5e5 + 7;

int a[N];
int dis[N];
int req[N];

int main() {
  ios::sync_with_stdio(false);

  int n;
  cin >> n >> dis[0];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++)
    dis[i + 1] = min(abs(dis[i] - a[i]), dis[i]);
  req[n] = 1;
  for (int i = n - 1; i >= 0; i--) {
    req[i] = req[i + 1];
    if (abs(req[i] - a[i]) < req[i])
      req[i] += a[i];
  }
  int q;
  cin >> q;
  while (q--) {
    int x;
    cin >> x;
    x--;
    if (dis[x] >= req[x + 1])
      cout << "YES\n";
    else
      cout << "NO\n";
  }

  return 0;
}
Problem p03743 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long giant;
inline char nchar() {
  static const int bufl = 1 << 20;
  static char buf[bufl], *a = NULL, *b = NULL;
  return a == b && (b = (a = buf) + fread(buf, 1, bufl, stdin), a == b) ? EOF
                                                                        : *a++;
}
inline int read() {
  int x = 0, f = 1;
  char c = nchar();
  for (; !isdigit(c); c = nchar())
    if (c == '-')
      f = -1;
  for (; isdigit(c); c = nchar())
    x = x * 10 + c - '0';
  return x * f;
}
const int maxn = 5e5 + 10;
int n, m;
giant a[maxn], no[maxn], p[maxn];
int main() {
#ifndef ONLINE_JUDGE
  freopen("test.in", "r", stdin);
#endif
  n = read(), p[0] = read();
  for (int i = 1; i <= n; ++i) {
    giant &x = a[i] = read();
    p[i] = min(p[i - 1], abs(p[i - 1] - x));
  }
  no[n + 1] = 0;
  for (int i = n; i; --i) {
    giant &x = no[i + 1], k = min(x, a[i] / 2);
    if (a[i] - k > k + 1)
      no[i] = k;
    else
      no[i] = a[i] + x;
  }
  int q = read();
  while (q--) {
    int x = read();
    puts(p[x - 1] > no[x + 1] ? "YES" : "NO");
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long giant;
inline char nchar() {
  static const int bufl = 1 << 20;
  static char buf[bufl], *a = NULL, *b = NULL;
  return a == b && (b = (a = buf) + fread(buf, 1, bufl, stdin), a == b) ? EOF
                                                                        : *a++;
}
inline int read() {
  int x = 0, f = 1;
  char c = nchar();
  for (; !isdigit(c); c = nchar())
    if (c == '-')
      f = -1;
  for (; isdigit(c); c = nchar())
    x = x * 10 + c - '0';
  return x * f;
}
const int maxn = 5e5 + 10;
int n, m;
giant a[maxn], no[maxn], p[maxn];
int main() {
  n = read(), p[0] = read();
  for (int i = 1; i <= n; ++i) {
    giant &x = a[i] = read();
    p[i] = min(p[i - 1], abs(p[i - 1] - x));
  }
  no[n + 1] = 0;
  for (int i = n; i; --i) {
    giant &x = no[i + 1], k = min(x, a[i] / 2);
    if (a[i] - k > k + 1)
      no[i] = k;
    else
      no[i] = a[i] + x;
  }
  int q = read();
  while (q--) {
    int x = read();
    puts(p[x - 1] > no[x + 1] ? "YES" : "NO");
  }
  return 0;
}
Problem p03743 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for (int i = x; i < (int)(n); ++i)

int n, d, q, l[100001], x[100001];
bool an[100001];

int main() {
  scanf("%d%d", &n, &d);
  l[0] = d;
  f(i, 1, n + 1) {
    scanf("%d", x + i);
    if (x[i] < l[i - 1] << 1)
      l[i] = abs(l[i - 1] - x[i]);
    else
      l[i] = l[i - 1];
  }
  int z = 1;
  for (int i = n; i > 0; --i) {
    if (l[i - 1] >= z)
      an[i] = true;
    if (x[i] < z << 1)
      z += x[i];
  }
  scanf("%d", &q);
  while (q--) {
    int x;
    scanf("%d", &x);
    printf("%s\n", an[x] ? "YES" : "NO");
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for (int i = x; i < (int)(n); ++i)

int n, d, q, l[500001], x[500001];
bool an[500001];

int main() {
  scanf("%d%d", &n, &d);
  l[0] = d;
  f(i, 1, n + 1) {
    scanf("%d", x + i);
    if (x[i] < l[i - 1] << 1)
      l[i] = abs(l[i - 1] - x[i]);
    else
      l[i] = l[i - 1];
  }
  int z = 1;
  for (int i = n; i > 0; --i) {
    if (l[i - 1] >= z)
      an[i] = true;
    if (x[i] < z << 1)
      z += x[i];
  }
  scanf("%d", &q);
  while (q--) {
    int x;
    scanf("%d", &x);
    printf("%s\n", an[x] ? "YES" : "NO");
  }
}
Problem p03743 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int n = 0, mov[100500], sum[100500], dp[100500];
bool able[100500];
int main() {
#define pud(x, y) min((x), abs((x) - (y)))
  scanf("%d%d", &n, sum);
  for (int i = 1; i <= n; i++) {
    scanf("%d", mov + i);
    sum[i] = pud(sum[i - 1], mov[i]);
  }
  dp[n + 1] = 1;
  for (int i = n; i >= 1; i--) {
    able[i] = (sum[i - 1] >= dp[i + 1]);
    dp[i] = dp[i + 1] + mov[i];
    if (pud(dp[i + 1], mov[i]) == dp[i + 1])
      dp[i] = min(dp[i], dp[i + 1]);
    if (mov[i] - dp[i + 1] >= 0 and
        pud(mov[i] - dp[i + 1], mov[i]) == dp[i + 1])
      dp[i] = min(dp[i], mov[i] - dp[i + 1]);
  }
  int q = 0;
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int s = 0;
    scanf("%d", &s);
    puts(able[s] ? "YES" : "NO");
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int n = 0, mov[500500], sum[500500], dp[500500];
bool able[500500];
int main() {
#define pud(x, y) min((x), abs((x) - (y)))
  scanf("%d%d", &n, sum);
  for (int i = 1; i <= n; i++) {
    scanf("%d", mov + i);
    sum[i] = pud(sum[i - 1], mov[i]);
  }
  dp[n + 1] = 1;
  for (int i = n; i >= 1; i--) {
    able[i] = (sum[i - 1] >= dp[i + 1]);
    dp[i] = dp[i + 1] + mov[i];
    if (pud(dp[i + 1], mov[i]) == dp[i + 1])
      dp[i] = min(dp[i], dp[i + 1]);
    if (mov[i] - dp[i + 1] >= 0 and
        pud(mov[i] - dp[i + 1], mov[i]) == dp[i + 1])
      dp[i] = min(dp[i], mov[i] - dp[i + 1]);
  }
  int q = 0;
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int s = 0;
    scanf("%d", &s);
    puts(able[s] ? "YES" : "NO");
  }
  return 0;
}
Problem p03743 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 100;
#define ll long long

ll a[N], p[N], d[N];
ll n, m;
int main() {
  // int n,m;
  ios::sync_with_stdio(false);
  cin >> n >> m;
  d[0] = m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    d[i] = min(d[i - 1], abs(d[i - 1] - a[i])); // 走1-i步的最小距离
  }
  p[n + 1] = 1; // 走x-n步最小不能的距离
  for (int i = n; i >= 1; i--) {
    if (a[i] / 2 >= p[i + 1])
      p[i] = p[i + 1];
    else
      p[i] = p[i + 1] + a[i];
  }
  int q;
  cin >> q;
  while (q--) {
    int x;
    cin >> x;
    if (d[x - 1] >= p[x + 1])
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100;
#define ll long long

ll a[N], p[N], d[N];
ll n, m;
int main() {
  // int n,m;
  ios::sync_with_stdio(false);
  cin >> n >> m;
  d[0] = m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    d[i] = min(d[i - 1], abs(d[i - 1] - a[i])); // 走1-i步的最小距离
  }
  p[n + 1] = 1; // 走x-n步最小不能的距离
  for (int i = n; i >= 1; i--) {
    if (a[i] / 2 >= p[i + 1])
      p[i] = p[i + 1];
    else
      p[i] = p[i + 1] + a[i];
  }
  int q;
  cin >> q;
  while (q--) {
    int x;
    cin >> x;
    if (d[x - 1] >= p[x + 1])
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}
Problem p03743 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <cstdlib>
#define fo(i, a, b) for (int i = a; i <= b; i++)
#define fod(i, a, b) for (int i = a; i >= b; i--)
#define min(q, w) ((q) > (w) ? (w) : (q))
#define abs(q) ((q) < 0 ? -(q) : (q))
using namespace std;
const int N = 100500;
int read(int &n) {
  char ch = ' ';
  int q = 0, w = 1;
  for (; (ch != '-') && ((ch < '0') || (ch > '9')); ch = getchar())
    ;
  if (ch == '-')
    w = -1, ch = getchar();
  for (; ch >= '0' && ch <= '9'; ch = getchar())
    q = q * 10 + ch - 48;
  n = q * w;
  return n;
}
int m, n, ans;
int f[N], a[N], c[N];
int main() {
  int q, w;
  read(n), read(m);
  c[0] = m;
  fo(i, 1, n) read(a[i]), c[i] = min(c[i - 1], abs(c[i - 1] - a[i]));
  f[n + 1] = 0;
  fod(i, n, 1) f[i] = f[i + 1] + (f[i + 1] * 2 + 1 >= a[i] ? a[i] : 0);
  read(m);
  fo(i, 1, m) {
    read(q);
    if (c[q - 1] > f[q + 1])
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}

Fixed submission:
#include <cstdio>
#include <cstdlib>
#define fo(i, a, b) for (int i = a; i <= b; i++)
#define fod(i, a, b) for (int i = a; i >= b; i--)
#define min(q, w) ((q) > (w) ? (w) : (q))
#define abs(q) ((q) < 0 ? -(q) : (q))
using namespace std;
const int N = 500500;
int read(int &n) {
  char ch = ' ';
  int q = 0, w = 1;
  for (; (ch != '-') && ((ch < '0') || (ch > '9')); ch = getchar())
    ;
  if (ch == '-')
    w = -1, ch = getchar();
  for (; ch >= '0' && ch <= '9'; ch = getchar())
    q = q * 10 + ch - 48;
  n = q * w;
  return n;
}
int m, n, ans;
int f[N], a[N], c[N];
int main() {
  int q, w;
  read(n), read(m);
  c[0] = m;
  fo(i, 1, n) read(a[i]), c[i] = min(c[i - 1], abs(c[i - 1] - a[i]));
  f[n + 1] = 0;
  fod(i, n, 1) f[i] = f[i + 1] + (f[i + 1] * 2 + 1 >= a[i] ? a[i] : 0);
  read(m);
  fo(i, 1, m) {
    read(q);
    if (c[q - 1] > f[q + 1])
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}
Problem p03743 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 9;
int n, d[N], pre[N], f[N], q, x, i;
int main() {
  for (scanf("%d%d", &n, pre), f[n] = i = 1; i <= n; ++i)
    scanf("%d", &d[i]), pre[i] = min(pre[i - 1], abs(pre[i - 1] - d[i]));
  for (i = n; i; --i)
    f[i - 1] = d[i] / 2 < f[i] ? f[i] + d[i] : f[i];
  for (scanf("%d", &q), i = 1; i <= q; ++i)
    puts((scanf("%d", &x), pre[x - 1] >= f[x]) ? "YES" : "NO");
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 9;
int n, d[N], pre[N], f[N], q, x, i;
int main() {
  for (scanf("%d%d", &n, pre), f[n] = i = 1; i <= n; ++i)
    scanf("%d", &d[i]), pre[i] = min(pre[i - 1], abs(pre[i - 1] - d[i]));
  for (i = n; i; --i)
    f[i - 1] = d[i] / 2 < f[i] ? f[i] + d[i] : f[i];
  for (scanf("%d", &q), i = 1; i <= q; ++i)
    puts((scanf("%d", &x), pre[x - 1] >= f[x]) ? "YES" : "NO");
  return 0;
}
Problem p03744 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int N;
  ll L;
  cin >> N >> L;
  deque<pair<int, double>> mp;
  mp.push_back(pair<int, double>(L, 0));
  double sum = 0;

  for (int i = 0; i < N; i++) {
    double t;
    int v;
    cin >> t >> v;
    int drain = v;
    while (drain > 0) {
      int amt = min(mp.back().first, drain);
      sum -= amt * mp.back().second;
      drain -= amt;
      mp.back().first -= amt;
      if (mp.back().first == 0)
        mp.pop_back();
    }
    sum += t * v;
    while (!mp.empty() && mp.front().second >= t) {
      t = t * v + mp.front().first * mp.front().second;
      v += mp.front().first;
      t /= v;
    }
    mp.push_front(pair<int, double>(v, t));
    cout << fixed << setprecision(10) << (sum / L) << '\n';
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int N;
  ll L;
  cin >> N >> L;
  deque<pair<int, double>> mp;
  mp.push_back(pair<int, double>(L, 0));
  double sum = 0;

  for (int i = 0; i < N; i++) {
    double t;
    int v;
    cin >> t >> v;
    int drain = v;
    while (drain > 0) {
      int amt = min(mp.back().first, drain);
      sum -= amt * mp.back().second;
      drain -= amt;
      mp.back().first -= amt;
      if (mp.back().first == 0)
        mp.pop_back();
    }
    sum += t * v;
    while (!mp.empty() && mp.front().second >= t) {
      t = t * v + mp.front().first * mp.front().second;
      v += mp.front().first;
      t /= v;
      mp.pop_front();
    }
    mp.push_front(pair<int, double>(v, t));
    cout << fixed << setprecision(10) << (sum / L) << '\n';
  }
}
Problem p03744 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#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--)
using namespace std;
typedef long long LL;

inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!(ch >= '0' && ch <= '9')) {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + (ch - '0');
    ch = getchar();
  }
  return x * f;
}

const int N = 500005;
const double eps = 1e-8;

int n, head = 0, tail = 0;
double L, q[N][2];

int main() {

#ifndef ONLINE_JUDGE
  freopen("data.in", "r", stdin);
  freopen("data.out", "w", stdout);
#endif

  n = read();
  L = read();
  double S = 0, V = 0;
  rep(i, 1, n) {
    int t = read(), v = read();
    V += v;
    S += (double)t * v;
    while (V > L && head < tail) {
      if (V - L >= q[head][0]) {
        V -= q[head][0];
        S -= q[head][0] * q[head][1];
        head++;
      } else {
        q[head][0] -= V - L;
        S -= (V - L) * q[head][1];
        V = L;
        break;
      }
    }
    q[tail][0] = v;
    q[tail++][1] = t;
    printf("%lf\n", S / L);
    while (tail - head >= 2) {
      if (q[tail - 1][1] > q[tail - 2][1])
        break;
      q[tail - 2][1] =
          (q[tail - 2][0] * q[tail - 2][1] + q[tail - 1][0] * q[tail - 1][1]) /
          (q[tail - 2][0] + q[tail - 1][0]);
      q[tail - 2][0] += q[tail - 1][0];
      tail--;
    }
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#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--)
using namespace std;
typedef long long LL;

inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!(ch >= '0' && ch <= '9')) {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + (ch - '0');
    ch = getchar();
  }
  return x * f;
}

const int N = 500005;
const double eps = 1e-8;

int n, head = 0, tail = 0;
double L, q[N][2];

int main() {

  n = read();
  L = read();
  double S = 0, V = 0;
  rep(i, 1, n) {
    int t = read(), v = read();
    V += v;
    S += (double)t * v;
    while (V > L && head < tail) {
      if (V - L >= q[head][0]) {
        V -= q[head][0];
        S -= q[head][0] * q[head][1];
        head++;
      } else {
        q[head][0] -= V - L;
        S -= (V - L) * q[head][1];
        V = L;
        break;
      }
    }
    q[tail][0] = v;
    q[tail++][1] = t;
    printf("%lf\n", S / L);
    while (tail - head >= 2) {
      if (q[tail - 1][1] > q[tail - 2][1])
        break;
      q[tail - 2][1] =
          (q[tail - 2][0] * q[tail - 2][1] + q[tail - 1][0] * q[tail - 1][1]) /
          (q[tail - 2][0] + q[tail - 1][0]);
      q[tail - 2][0] += q[tail - 1][0];
      tail--;
    }
  }

  return 0;
}