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

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

long long mINF = -9999999999999999LL;

int main() {
  int N;
  cin >> N;
  vector<long long> A(N);
  for (auto &i : A)
    cin >> i;

  long long dp[N + 1][3];
  for (int i = 0; i < N + 1; i++)
    for (int j = 0; j < 3; j++)
      dp[i][j] = mINF;
  dp[0][0] = dp[0][1] = dp[0][2] = dp[0][1] = dp[0][2] = dp[1][2] = 0;
  dp[1][0] = A[0];
  dp[2][1] = A[1];
  if (N % 2 == 1)
    dp[3][2] = A[2];

  for (int i = 2; i < N; i++) {
    dp[i + 1][0] = max(dp[i + 1][0], dp[i - 1][0] + A[i]);
    dp[i + 1][1] = max(dp[i + 1][1], dp[i - 1][1] + A[i]);
    dp[i + 1][1] = max(dp[i + 1][1], dp[i - 2][0] + A[i]);
    if (N % 2 == 1 && i > 2) {
      dp[i + 1][2] = max(dp[i + 1][2], dp[i - 1][2] + A[i]);
      dp[i + 1][2] = max(dp[i + 1][2], dp[i - 2][1] + A[i]);
      dp[i + 1][2] = max(dp[i + 1][2], dp[i - 3][0] + A[i]);
    }
  }
  long long ans;
  if (N % 2 == 0)
    ans = max(dp[N - 1][0], dp[N][1]);
  if (N % 2 == 1)
    ans = max(max(dp[N - 2][0], dp[N - 1][1]), dp[N][2]);
  cout << ans << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
//**デバッグ準備**//
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head h, Tail... t) {
  cerr << " " << h;
  if (sizeof...(t) > 0)
    cerr << " :";
  debug_out(t...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> vec) {
  for (size_t i = 0; i < vec.size(); i++)
    os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
ll ctoi(char c) {
  switch (c) {
  case '0':
    return 0;
  case '1':
    return 1;
  case '2':
    return 2;
  case '3':
    return 3;
  case '4':
    return 4;
  case '5':
    return 5;
  case '6':
    return 6;
  case '7':
    return 7;
  case '8':
    return 8;
  case '9':
    return 9;
  default:
    return 0;
  }
}
bool pairCompare(const pll firstElof, pll secondElof) {
  return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
// rep, vin, all, iteLoop//
// gcdlcm, isPrime, eratos, divisor, modinv, bitSearch, bitList, dfs, bfs//
// dijkstra, UnionFind, COM, digitDP//
ll i, j, k, l;
ll N, M, K, H, W, L, X, Y, Z;
ll MOD = 1000000007;
ll INF = 9999999999999;
ll ans = 0;
vl flag, color;
vll path;
ll start = 0;
//***********//
ll gcd(ll x, ll y) {
  ll r;
  if (x < y) {
    swap(x, y);
  }
  while (y > 0) {
    r = x % y;
    x = y;
    y = r;
  }
  return x;
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }
int main() {
  cin >> N;
  vl A(N);
  for (i = 0; i < N; i++) {
    cin >> A[i];
  }
  vll dp(N + 1, vl(3, 0));
  for (i = 0; i < N + 1; i++) {
    for (j = 0; j < 3; j++) {
      dp[i][j] = -INF;
    }
  }
  dp[0][0] = 0;
  dp[0][1] = 0;
  dp[0][2] = 0;
  dp[0][1] = 0;
  dp[0][2] = 0;
  dp[1][2] = 0;
  dp[1][1] = 0;
  dp[1][0] = A[0];
  dp[2][1] = A[1];
  dp[2][2] = 0;
  if (N != 2)
    dp[3][2] = A[2];
  for (i = 2; i <= N; i++) {
    dp[i + 1][0] = max(dp[i + 1][0], dp[i - 1][0] + A[i]);
    dp[i + 1][1] = max(dp[i + 1][1], dp[i - 1][1] + A[i]);
    dp[i + 1][1] = max(dp[i + 1][1], dp[i - 2][0] + A[i]);
    if (N % 2 == 1 && i > 2) {
      dp[i + 1][2] = max(dp[i + 1][2], dp[i - 1][2] + A[i]);
      dp[i + 1][2] = max(dp[i + 1][2], dp[i - 2][1] + A[i]);
      dp[i + 1][2] = max(dp[i + 1][2], dp[i - 3][0] + A[i]);
    }
  }
  if (N % 2 == 1) {
    cout << max(max(dp[N - 2][0], dp[N - 1][1]), dp[N][2]);
  } else {
    cout << max(dp[N - 1][0], dp[N][1]);
  }
}