Problem p03162 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <iostream>
#define scan(n) scanf("%I64d", &n);
#define scan2(a, b) scanf("%I64d%I64d", &a, &b);
#define scan3(a, b, c) scanf("%I64d%I64d%I64d", &a, &b, &c);
#define sc(n) scanf("%c", &n);
#define sf(n) scanf("%lf", &n);
#define ss(n) scanf("%s", n);
#define forall(i, a, b) for (long long int i = a; i < b; i++)
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
#define FAST_IO                                                                \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);
#define minimum(a) *min_element(a.begin(), a.end())
#define maximum(a) *max_element(a.begin(), a.end())
#define display(a)                                                             \
  for (auto i : a)                                                             \
    cout << i << " ";
typedef long long int ll;
typedef long double ld;
const int MOD = 1e9 + 7;
using namespace std;
ll power(ll a, ll n) {
  ll p = 1;
  while (n > 0) {
    if (n % 2) {
      p = p * a;
    }
    n >>= 1;
    a *= a;
  }
  return p;
}
ll power(ll a, ll n, ll mod) {
  ll p = 1;
  while (n > 0) {
    if (n % 2) {
      p = p * a;
      p %= mod;
    }
    n >>= 1;
    a *= a;
    a %= mod;
  }
  return p % mod;
}
vector<ll> scanVector(ll n, vector<ll> &v) {
  ll temp;
  for (ll i = 0; i < n; i++) {
    cin >> temp;
    v.pb(temp);
  }
  return v;
}

int main() {
  FAST_IO
  ll t;
  // cin>>t;
  t = 1;
  while (t--) {
    ll n;
    cin >> n;
    ll a1, b1, c1;
    vector<ll> a;
    vector<ll> b;
    vector<ll> c;
    for (ll i = 1; i <= n; i++) {
      cin >> a1 >> b1 >> c1;
      a.pb(a1);
      b.pb(b1);
      c.pb(c1);
    }
    ll dp[n][n];
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    for (ll i = 1; i < n; i++) {
      dp[i][0] = a[i] + max(dp[i - 1][1], dp[i - 1][2]);
      dp[i][1] = b[i] + max(dp[i - 1][0], dp[i - 1][2]);
      dp[i][2] = c[i] + max(dp[i - 1][1], dp[i - 1][0]);
    }
    cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]}) << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#include <iostream>
#define scan(n) scanf("%I64d", &n);
#define scan2(a, b) scanf("%I64d%I64d", &a, &b);
#define scan3(a, b, c) scanf("%I64d%I64d%I64d", &a, &b, &c);
#define sc(n) scanf("%c", &n);
#define sf(n) scanf("%lf", &n);
#define ss(n) scanf("%s", n);
#define forall(i, a, b) for (long long int i = a; i < b; i++)
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
#define FAST_IO                                                                \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);
#define minimum(a) *min_element(a.begin(), a.end())
#define maximum(a) *max_element(a.begin(), a.end())
#define display(a)                                                             \
  for (auto i : a)                                                             \
    cout << i << " ";
typedef long long int ll;
typedef long double ld;
const int MOD = 1e9 + 7;
using namespace std;
ll power(ll a, ll n) {
  ll p = 1;
  while (n > 0) {
    if (n % 2) {
      p = p * a;
    }
    n >>= 1;
    a *= a;
  }
  return p;
}
ll power(ll a, ll n, ll mod) {
  ll p = 1;
  while (n > 0) {
    if (n % 2) {
      p = p * a;
      p %= mod;
    }
    n >>= 1;
    a *= a;
    a %= mod;
  }
  return p % mod;
}
vector<ll> scanVector(ll n, vector<ll> &v) {
  ll temp;
  for (ll i = 0; i < n; i++) {
    cin >> temp;
    v.pb(temp);
  }
  return v;
}

int main() {
  FAST_IO
  ll t;
  // cin>>t;
  t = 1;
  while (t--) {
    ll n;
    cin >> n;
    ll a1, b1, c1;
    vector<ll> a;
    vector<ll> b;
    vector<ll> c;
    for (ll i = 1; i <= n; i++) {
      cin >> a1 >> b1 >> c1;
      a.pb(a1);
      b.pb(b1);
      c.pb(c1);
    }
    ll dp[n][3];
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    for (ll i = 1; i < n; i++) {
      dp[i][0] = a[i] + max(dp[i - 1][1], dp[i - 1][2]);
      dp[i][1] = b[i] + max(dp[i - 1][0], dp[i - 1][2]);
      dp[i][2] = c[i] + max(dp[i - 1][1], dp[i - 1][0]);
    }
    cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]}) << endl;
  }
  return 0;
}