Problem p03162 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <unordered_map>

using namespace std;

#define endl '\n'
#define ll long long
#define int long long
const int32_t INFint = 1e9;
const ll INFll = 1e18;
#define MOD 1000000007ll
#define fast                                                                   \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);

#define vi vector<int>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define foreach(it, v)                                                         \
  for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)

#define deb1(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl
#define deb3(x, y, z)                                                          \
  cout << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": "    \
       << z << endl
#define deb4(a, b, c, d)                                                       \
  cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << endl
#define deb5(a, b, c, d, e)                                                    \
  cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define deb6(a, b, c, d, e, f)                                                 \
  cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | "   \
       << #f << ": " << f << endl

#define For(i, a, b) for (ll i = a; i < b; i++)
#define loop(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
#define gll(a, n)                                                              \
  for (ll i = 0; i < n; i++)                                                   \
    cin >> a[i];
#define gint(a, n)                                                             \
  for (int i = 0; i < n; i++)                                                  \
    cin >> a[i];
#define setZero(a, n)                                                          \
  for (int i = 0; i < n; i++)                                                  \
    a[i] = 0;
#define printArray(a, s, e)                                                    \
  for (int i = s; i < e; i++) {                                                \
    cout << a[i] << " ";                                                       \
  }                                                                            \
  cout << endl;
//---------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------
int32_t main() {
  fast;

  int t;
  // cin >> t;
  t = 1;
  while (t--) {
    int n;
    cin >> n;
    int arr[n][3];
    for (int i = 0; i < n; i++)
      for (int j = 0; j < 3; j++)
        cin >> arr[i][j];

    int dp[n][n];
    for (int i = 0; i < 3; i++)
      dp[0][i] = arr[0][i];

    for (int i = 1; i < n; i++) {
      dp[i][0] = arr[i][0] + max(dp[i - 1][1], dp[i - 1][2]);
      dp[i][1] = arr[i][1] + max(dp[i - 1][0], dp[i - 1][2]);
      dp[i][2] = arr[i][2] + max(dp[i - 1][1], dp[i - 1][0]);
    }

    cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));
  }
}


Fixed submission:
#include <bits/stdc++.h>
#include <unordered_map>

using namespace std;

#define endl '\n'
#define ll long long
#define int long long
const int32_t INFint = 1e9;
const ll INFll = 1e18;
#define MOD 1000000007ll
#define fast                                                                   \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);

#define vi vector<int>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define foreach(it, v)                                                         \
  for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)

#define deb1(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl
#define deb3(x, y, z)                                                          \
  cout << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": "    \
       << z << endl
#define deb4(a, b, c, d)                                                       \
  cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << endl
#define deb5(a, b, c, d, e)                                                    \
  cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define deb6(a, b, c, d, e, f)                                                 \
  cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | "   \
       << #f << ": " << f << endl

#define For(i, a, b) for (ll i = a; i < b; i++)
#define loop(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
#define gll(a, n)                                                              \
  for (ll i = 0; i < n; i++)                                                   \
    cin >> a[i];
#define gint(a, n)                                                             \
  for (int i = 0; i < n; i++)                                                  \
    cin >> a[i];
#define setZero(a, n)                                                          \
  for (int i = 0; i < n; i++)                                                  \
    a[i] = 0;
#define printArray(a, s, e)                                                    \
  for (int i = s; i < e; i++) {                                                \
    cout << a[i] << " ";                                                       \
  }                                                                            \
  cout << endl;
//---------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------
int32_t main() {
  fast;

  int t;
  // cin >> t;
  t = 1;
  while (t--) {
    int n;
    cin >> n;
    int arr[n][3];
    for (int i = 0; i < n; i++)
      for (int j = 0; j < 3; j++)
        cin >> arr[i][j];

    int dp[n][3];
    for (int i = 0; i < 3; i++)
      dp[0][i] = arr[0][i];

    for (int i = 1; i < n; i++) {
      dp[i][0] = arr[i][0] + max(dp[i - 1][1], dp[i - 1][2]);
      dp[i][1] = arr[i][1] + max(dp[i - 1][0], dp[i - 1][2]);
      dp[i][2] = arr[i][2] + max(dp[i - 1][1], dp[i - 1][0]);
    }

    cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));
  }
}