Problem p03162 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
#define speed_up                                                               \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define pb push_back
#define Max(x, y, z) max(x, max(y, z))
#define f first
#define s second
#define lbd lower_bound
#define sz(x) (ll) x.size()
#define pi 3.1415926536
#define mod 1000000007
using namespace std;
/*void bfs(ll s, vector<vector<ll>> &adj)
{
 dis[s]=0;B
 vis[s]=1;
 queue<ll> q;
 q.push(s);
 while(!q.empty())
 {
   ll x=q.front();
   q.pop();
   for(auto to:adj[x])
   {
       if(!vis[to])
       {dis[to]=dis[x]+1;q.push(to); vis[to]=1;}
   }
 }
}*/
void solve() {
  ll n, m, k, res = 0, l = 0, r = 0, sum = 0, z, sum1 = 0, cnt1 = 0, h, res1, c,
              x, y;
  cin >> n;
  ll ar[n][3];
  rep(i, 0, n) rep(j, 0, 3) cin >> ar[i][j];
  ll dp[n][3];
  dp[0][0] = ar[0][0];
  dp[0][1] = ar[0][1];
  dp[0][2] = ar[0][2];
  if (n > 1) {
    rep(i, 1, n) {
      dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + ar[i][0];
      dp[i][1] = max(dp[i - 1][2], dp[i - 1][0]) + ar[i][1];
      dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + ar[i][2];
    }
  }
  cout << Max(dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]);
}
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  speed_up ll t;
  // cin>>t;
  t = 1;
  while (t--)
    solve();
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define speed_up                                                               \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define pb push_back
#define Max(x, y, z) max(x, max(y, z))
#define f first
#define s second
#define lbd lower_bound
#define sz(x) (ll) x.size()
#define pi 3.1415926536
#define mod 1000000007
using namespace std;
/*void bfs(ll s, vector<vector<ll>> &adj)
{
 dis[s]=0;B
 vis[s]=1;
 queue<ll> q;
 q.push(s);
 while(!q.empty())
 {
   ll x=q.front();
   q.pop();
   for(auto to:adj[x])
   {
       if(!vis[to])
       {dis[to]=dis[x]+1;q.push(to); vis[to]=1;}
   }
 }
}*/
void solve() {
  ll n, m, k, res = 0, l = 0, r = 0, sum = 0, z, sum1 = 0, cnt1 = 0, h, res1, c,
              x, y;
  cin >> n;
  ll ar[n][3];
  rep(i, 0, n) rep(j, 0, 3) cin >> ar[i][j];
  ll dp[n][3];
  dp[0][0] = ar[0][0];
  dp[0][1] = ar[0][1];
  dp[0][2] = ar[0][2];
  if (n > 1) {
    rep(i, 1, n) {
      dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + ar[i][0];
      dp[i][1] = max(dp[i - 1][2], dp[i - 1][0]) + ar[i][1];
      dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + ar[i][2];
    }
  }
  cout << Max(dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]);
}
int main() {
  /*#ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif*/

  speed_up ll t;
  // cin>>t;
  t = 1;
  while (t--)
    solve();
}