Problem p03162 (C++)

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

#define ll long long
#define ld long double

#define rep(i, a, b) for (ll i = a; i < b; i++)
#define repb(i, a, b) for (ll i = a; i >= b; i--)

#define err() cout << "==================================" << endl;
#define errA(A)                                                                \
  for (auto i : A)                                                             \
    cout << i << " ";                                                          \
  cout << endl;
#define err1(a) cout << #a << " " << a << endl
#define err2(a, b) cout << #a << " " << a << " " << #b << " " << b << endl
#define err3(a, b, c)                                                          \
  cout << #a << " " << a << " " << #b << " " << b << " " << #c << " " << c     \
       << endl
#define err4(a, b, c, d)                                                       \
  cout << #a << " " << a << " " << #b << " " << b << " " << #c << " " << c     \
       << " " << #d << " " << d << endl

#define pb push_back
#define all(A) A.begin(), A.end()
#define allr(A) A.rbegin(), A.rend()
#define ft first
#define sd second

#define pll pair<ll, ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>
#define Vpll vector<pll>

#define endl "\n"

const ll logN = 20;
const ll M = 1000000007;
const ll INF = 1e12;
#define PI 3.14159265

int main() {
  int n;
  cin >> n;
  vector<int> dp(3);
  rep(i, 0, n) {
    vector<int> new_dp(3, 0);
    vector<int> c(3);
    rep(j, 0, 3) cin >> c[j];
    rep(k, 0, 3) {
      rep(j, 0, 3) {
        if (k != j) {
          new_dp[j] = max(new_dp[j], dp[i] + c[j]);
        }
      }
    }
    dp = new_dp;
  }
  cout << max(dp[0], max(dp[1], dp[2]));
}

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

#define ll long long
#define ld long double

#define rep(i, a, b) for (ll i = a; i < b; i++)
#define repb(i, a, b) for (ll i = a; i >= b; i--)

#define err() cout << "==================================" << endl;
#define errA(A)                                                                \
  for (auto i : A)                                                             \
    cout << i << " ";                                                          \
  cout << endl;
#define err1(a) cout << #a << " " << a << endl
#define err2(a, b) cout << #a << " " << a << " " << #b << " " << b << endl
#define err3(a, b, c)                                                          \
  cout << #a << " " << a << " " << #b << " " << b << " " << #c << " " << c     \
       << endl
#define err4(a, b, c, d)                                                       \
  cout << #a << " " << a << " " << #b << " " << b << " " << #c << " " << c     \
       << " " << #d << " " << d << endl

#define pb push_back
#define all(A) A.begin(), A.end()
#define allr(A) A.rbegin(), A.rend()
#define ft first
#define sd second

#define pll pair<ll, ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>
#define Vpll vector<pll>

#define endl "\n"

const ll logN = 20;
const ll M = 1000000007;
const ll INF = 1e12;
#define PI 3.14159265

int main() {
  int n;
  cin >> n;
  vector<int> dp(3);
  rep(i, 0, n) {
    vector<int> new_dp(3, 0);
    vector<int> c(3);
    rep(j, 0, 3) cin >> c[j];
    rep(k, 0, 3) {
      rep(j, 0, 3) {
        if (k != j) {
          new_dp[j] = max(new_dp[j], dp[k] + c[j]);
        }
      }
    }
    dp = new_dp;
  }
  cout << max(dp[0], max(dp[1], dp[2]));
}