Problem p03162 (C++)

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

#define FAST                                                                   \
  std::ios_base::sync_with_stdio(false);                                       \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define M 1000000007
#define mp make_pair
#define pb push_back
#define PB pop_back
#define sl(a) (int)a.length()
#define sz(a) (int)a.size()
#define lcase(a) (char)tolower(a)
#define ucase(a) (char)toupper(a)
#define precise(a) fixed << setprecision(a) <<
#define F first
#define S second
#define I insert
#define pii pair<int, int>
#define trav(a, x) for (auto &a : x)
#define fl(i, n) for (int i = 0; i < n; i++)
#define rfl(n) for (int i = n - 1; i >= 0; i--)
#define time                                                                   \
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
#define invect(data, n, commands)                                              \
  for (int i = 0; i < n; i++) {                                                \
    int tmp;                                                                   \
    cin >> tmp;                                                                \
    data.pb(tmp);                                                              \
    commands                                                                   \
  }
#define inset(data, n, commands)                                               \
  for (int i = 0; i < n; i++) {                                                \
    int tmp;                                                                   \
    cin >> tmp;                                                                \
    data.I(tmp);                                                               \
    commands                                                                   \
  }
#define display(x)                                                             \
  trav(a, x) cout << a << " ";                                                 \
  cout << endl;
#define ingrid(data, n, commands)                                              \
  for (int i = 0; i < n; i++) {                                                \
    cin >> data[i];                                                            \
    commands                                                                   \
  }
#define section(a, b, w)                                                       \
  set_intersection(a.begin(), a.end(), b.begin(), b.end(), back_inserter(w));
#define union(a, b, w)                                                         \
  set_union(a.begin(), a.end(), b.begin(), b.end(), back_inserter(w));
#define copy(a, w) copy(a.begin(), a.end(), back_inserter(w));
#define all(data) data.begin(), data.end()
#define PI 3.14159265358979323844
#define endl '\n'
#define last(a) a[sz(a) - 1]
#define mp make_pair

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
  std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  std::cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}

// Graph DFS
const int fx[] = {+1, -1, +0, +0};
const int fy[] = {+0, +0, +1, -1};

// primes for hashing 937,991,1013,1409,1741

// Returns index of first element not less than key and more than key
// respectively
#define lb(data, key) lower_bound(all(data), key) - data.begin();
#define up(data, key) upper_bound(all(data), key) - data.begin();
#define fnd(data, key) find(all(data), key) - data.begin();
// Long Long Int
#define int long long int

void solve() {
  int n;
  cin >> n;
  std::vector<std::vector<int>> v(n, std::vector<int>(n, 0));
  fl(i, n) {
    fl(j, 3) { cin >> v[i][j]; }
  }
  int dp[n][3];
  fl(i, 3) { dp[0][i] = v[0][i]; }
  for (int i = 1; i < n; i++) {
    dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + v[i][0];
    dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + v[i][1];
    dp[i][2] = max(dp[i - 1][1], dp[i - 1][0]) + v[i][2];
  }
  cout << max(max(dp[n - 1][1], dp[n - 1][0]), dp[n - 1][2]) << endl;
}

signed main() {

  FAST

      int t = 1;
  // cin>>t;
  while (t--)
    solve();

  return 0;
}

/*6
30 10 60 10 60 50*/

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

#define FAST                                                                   \
  std::ios_base::sync_with_stdio(false);                                       \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define M 1000000007
#define mp make_pair
#define pb push_back
#define PB pop_back
#define sl(a) (int)a.length()
#define sz(a) (int)a.size()
#define lcase(a) (char)tolower(a)
#define ucase(a) (char)toupper(a)
#define precise(a) fixed << setprecision(a) <<
#define F first
#define S second
#define I insert
#define pii pair<int, int>
#define trav(a, x) for (auto &a : x)
#define fl(i, n) for (int i = 0; i < n; i++)
#define rfl(n) for (int i = n - 1; i >= 0; i--)
#define time                                                                   \
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
#define invect(data, n, commands)                                              \
  for (int i = 0; i < n; i++) {                                                \
    int tmp;                                                                   \
    cin >> tmp;                                                                \
    data.pb(tmp);                                                              \
    commands                                                                   \
  }
#define inset(data, n, commands)                                               \
  for (int i = 0; i < n; i++) {                                                \
    int tmp;                                                                   \
    cin >> tmp;                                                                \
    data.I(tmp);                                                               \
    commands                                                                   \
  }
#define display(x)                                                             \
  trav(a, x) cout << a << " ";                                                 \
  cout << endl;
#define ingrid(data, n, commands)                                              \
  for (int i = 0; i < n; i++) {                                                \
    cin >> data[i];                                                            \
    commands                                                                   \
  }
#define section(a, b, w)                                                       \
  set_intersection(a.begin(), a.end(), b.begin(), b.end(), back_inserter(w));
#define union(a, b, w)                                                         \
  set_union(a.begin(), a.end(), b.begin(), b.end(), back_inserter(w));
#define copy(a, w) copy(a.begin(), a.end(), back_inserter(w));
#define all(data) data.begin(), data.end()
#define PI 3.14159265358979323844
#define endl '\n'
#define last(a) a[sz(a) - 1]
#define mp make_pair

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
  std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  std::cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}

// Graph DFS
const int fx[] = {+1, -1, +0, +0};
const int fy[] = {+0, +0, +1, -1};

// primes for hashing 937,991,1013,1409,1741

// Returns index of first element not less than key and more than key
// respectively
#define lb(data, key) lower_bound(all(data), key) - data.begin();
#define up(data, key) upper_bound(all(data), key) - data.begin();
#define fnd(data, key) find(all(data), key) - data.begin();
// Long Long Int
#define int long long int

void solve() {
  int n;
  cin >> n;
  std::vector<std::vector<int>> v(n, std::vector<int>(3, 0));
  fl(i, n) {
    fl(j, 3) { cin >> v[i][j]; }
  }
  int dp[n][3];
  fl(i, 3) { dp[0][i] = v[0][i]; }
  for (int i = 1; i < n; i++) {
    dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + v[i][0];
    dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + v[i][1];
    dp[i][2] = max(dp[i - 1][1], dp[i - 1][0]) + v[i][2];
  }
  cout << max(max(dp[n - 1][1], dp[n - 1][0]), dp[n - 1][2]) << endl;
}

signed main() {

  FAST

      int t = 1;
  // cin>>t;
  while (t--)
    solve();

  return 0;
}

/*6
30 10 60 10 60 50*/