Problem p02665 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template <typename T1, typename T2> inline void chmin(T1 &a, const T2 &b) {
  if (a > b)
    a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, const T2 &b) {
  if (a < b)
    a = b;
}

#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()

/* do your best */

int main() {

  lint n;
  cin >> n;
  vector<lint> a(n + 1);
  for (int i = 0; i <= n; i++) {
    cin >> a[i];
  }

  if (n == 0) {
    if (a[0] == 1) {
      cout << 1 << endl;
    } else {
      cout << -1 << endl;
    }
    return 0;
  }

  if (a[0] != 0) {
    cout << -1 << endl;
    return 0;
  }

  vector<lint> b(n + 1);
  b[0] = 1;
  for (int i = 1; i <= n; i++) {
    b[i] = b[i - 1] * 2 - a[i];
    b[i] = min(b[i], INF);
    if (b[i] < 0) {
      cout << -1 << endl;
      return 0;
    }
  }

  vector<lint> c(n + 1);
  lint ans = a[n];
  c[n] = a[n];
  for (int i = n - 1; i >= 0; i--) {
    c[i] = min(c[i + 1] + a[i], b[i] + a[i]);
    ans += c[i];
  }

  cout << ans << endl;

  return 0;
}


Error: -6
cf91d03e-8067-4835-bfdc-198518d206c6.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02665/C++/s525809847.cpp:73: int main(): Assertion `false' failed.


Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template <typename T1, typename T2> inline void chmin(T1 &a, const T2 &b) {
  if (a > b)
    a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, const T2 &b) {
  if (a < b)
    a = b;
}

#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()

/* do your best */

int main() {

  lint n;
  cin >> n;
  vector<lint> a(n + 1);
  for (int i = 0; i <= n; i++) {
    cin >> a[i];
  }

  if (n == 0) {
    if (a[0] == 1) {
      cout << 1 << endl;
    } else {
      cout << -1 << endl;
    }
    return 0;
  }

  if (a[0] != 0) {
    cout << -1 << endl;
    return 0;
  }

  vector<lint> b(n + 1);
  b[0] = 1;
  for (int i = 1; i <= n; i++) {
    b[i] = b[i - 1] * 2 - a[i];
    b[i] = min(b[i], (lint)1e9);
    if (b[i] < 0) {
      cout << -1 << endl;
      return 0;
    }
  }

  assert(false);

  vector<lint> c(n + 1);
  lint ans = a[n];
  c[n] = a[n];
  for (int i = n - 1; i >= 0; i--) {
    c[i] = min(c[i + 1] + a[i], b[i] + a[i]);
    ans += c[i];
  }

  cout << ans << endl;

  return 0;
}