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

#include <algorithm>
#include <bitset>
#include <chrono>
#include <cmath>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  ll ans = 0;
  if (N % 2 == 0) {
    vector<ll> dp00(N + 1, 0), dp01(N + 1, 0), dp10(N + 1, 0), dp11(N + 1, 0);
    rep(i, N) {
      dp00[i + 1] = i % 2 ? dp01[i] : -1e17;
      dp01[i + 1] = dp00[i] + A[i];
      dp10[i + 1] = max(dp00[i], dp11[i]);
      dp11[i + 1] = dp10[i] + A[i];
    }
    /*
    rep(i,N+1) cout << dp00[i] << " ";
    cout << endl;
    rep(i,N+1) cout << dp01[i] << " ";
    cout << endl;
    rep(i,N+1) cout << dp10[i] << " ";
    cout << endl;
    rep(i,N+1) cout << dp11[i] << " ";
    cout << endl;
    */
    ans = max(dp10[N], dp11[N]);
  } else {
    vector<ll> dp00(N + 1, 0), dp01(N + 1, 0), dp10(N + 1, 0), dp11(N + 1, 0),
        dp20(N + 1, 0), dp21(N + 1, 0);
    rep(i, N) {
      dp00[i + 1] = i % 2 ? dp01[i] : -1e17;
      dp01[i + 1] = dp00[i] + A[i];
      dp10[i + 1] = max(dp00[i], dp11[i]);
      dp11[i + 1] = dp10[i] + A[i];
      dp20[i + 1] = max(dp10[i], dp21[i]);
      dp21[i + 1] = dp20[i] + A[i];
    }
    ans = max({dp20[N], dp21[N]});
  }
  cout << ans << endl;
  return 0;
}


Error: -8

Fixed submission:

#include <algorithm>
#include <bitset>
#include <chrono>
#include <cmath>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  vector<ll> evens;
  vector<ll> odds;
  evens.pb(0);
  odds.pb(0);
  rep(i, N) {
    if (i % 2 == 0) {
      evens.pb(A[i]);
    } else
      odds.pb(A[i]);
  }
  rep(i, sz(evens)) { evens[i + 1] += evens[i]; }
  rep(i, sz(odds)) { odds[i + 1] += odds[i]; }

  ll ans = 0;
  if (N % 2 == 0) {
    int c = N / 2;
    rep(i, c) { ans = max(ans, evens[i] + odds[c - i] - odds[i]); }
    ans /= 0;
  } else {
    vector<ll> dp00(N + 1, 0), dp01(N + 1, 0), dp10(N + 1, 0), dp11(N + 1, 0),
        dp20(N + 1, 0), dp21(N + 1, 0);

    rep(i, N) {
      dp00[i + 1] = dp01[i];
      dp01[i + 1] = dp00[i] + A[i];
      dp10[i + 1] = max({dp00[i], dp11[i]});
      dp11[i + 1] = dp10[i] + A[i];
      dp20[i + 1] = max({dp10[i], dp21[i]});
      dp21[i + 1] = dp20[i] + A[i];
    }
    cout << dp00[N] << endl;
    cout << dp01[N] << endl;
    cout << dp10[N] << endl;
    cout << dp11[N] << endl;
    cout << dp20[N] << endl;
    cout << dp21[N] << endl;
    ans = max({dp20[N], dp21[N]});
    // ans = dp20[N];
  }
  cout << ans << endl;
  return 0;
}