Problem p03162 (C++)

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

using namespace std;

vector<string> vec_splitter(string s) {
  s += ',';
  vector<string> res;
  while (!s.empty()) {
    res.push_back(s.substr(0, s.find(',')));
    s = s.substr(s.find(',') + 1);
  }
  return res;
}

void debug_out(vector<string> __attribute__((unused)) args,
               __attribute__((unused)) int idx,
               __attribute__((unused)) int LINE_NUM) {
  cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
  if (idx > 0)
    cerr << ", ";
  else
    cerr << "Line(" << LINE_NUM << ") ";
  stringstream ss;
  ss << H;
  cerr << args[idx] << " = " << ss.str();
  debug_out(args, idx + 1, LINE_NUM, T...);
}

#ifndef ONLINE_JUDGE
#define debug(...)                                                             \
  debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#endif

#define ll long long int
#define endl '\n'
#define pb push_back
#define vectl vector<ll>
#define vecti vector<int>
#define debugh cout << "here" << endl;
#define loopi(i, n) for (ll i = 0; i < n; i++)
#define loopj(j, n) for (ll j = 0; j < n; j++)
#define loop2(i, a, b) for (int i = a; i < b; i++)
#define mp make_pair
#define ip(a, n)                                                               \
  for (ll i = 0; i < n; i++)                                                   \
  cin >> a[i]
#define op(a, n)                                                               \
  for (ll i = 0; i < n; i++)                                                   \
  cout << a[i] << " "
#define gcd(a, b) __gcd((a), (b))`
#define lcm(a, b) (((a) * (b)) / gcd((a), (b)))
#define mem(x, n) memset(x, n, sizeof(x))
#define cn cout << "\n";
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define testcase                                                               \
  ll t;                                                                        \
  cin >> t;                                                                    \
  while (t--)

const ll INF = 1e18;
const ll N = 100005;
const ll MOD = 1e9 + 7;

int main() {
  fast
      // testcase
      //  {
      ll n;
  cin >> n;
  int a[n][n];

  loopi(i, n) {
    for (ll j = 0; j < 3; j++) {
      // debugh
      cin >> a[i][j];
    }
  }

  ll dp[n][3];
  dp[0][0] = a[0][0];
  dp[0][1] = a[0][1];
  dp[0][2] = a[0][2];

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

  ll ans = max(dp[n - 1][0], dp[n - 1][1]);
  ans = max(ans, dp[n - 1][2]);

  cout << ans << endl;

  // }

  return 0;
}


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

using namespace std;

vector<string> vec_splitter(string s) {
  s += ',';
  vector<string> res;
  while (!s.empty()) {
    res.push_back(s.substr(0, s.find(',')));
    s = s.substr(s.find(',') + 1);
  }
  return res;
}

void debug_out(vector<string> __attribute__((unused)) args,
               __attribute__((unused)) int idx,
               __attribute__((unused)) int LINE_NUM) {
  cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
  if (idx > 0)
    cerr << ", ";
  else
    cerr << "Line(" << LINE_NUM << ") ";
  stringstream ss;
  ss << H;
  cerr << args[idx] << " = " << ss.str();
  debug_out(args, idx + 1, LINE_NUM, T...);
}

#ifndef ONLINE_JUDGE
#define debug(...)                                                             \
  debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#endif

#define ll long long int
#define endl '\n'
#define pb push_back
#define vectl vector<ll>
#define vecti vector<int>
#define debugh cout << "here" << endl;
#define loopi(i, n) for (ll i = 0; i < n; i++)
#define loopj(j, n) for (ll j = 0; j < n; j++)
#define loop2(i, a, b) for (int i = a; i < b; i++)
#define mp make_pair
#define ip(a, n)                                                               \
  for (ll i = 0; i < n; i++)                                                   \
  cin >> a[i]
#define op(a, n)                                                               \
  for (ll i = 0; i < n; i++)                                                   \
  cout << a[i] << " "
#define gcd(a, b) __gcd((a), (b))`
#define lcm(a, b) (((a) * (b)) / gcd((a), (b)))
#define mem(x, n) memset(x, n, sizeof(x))
#define cn cout << "\n";
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define testcase                                                               \
  ll t;                                                                        \
  cin >> t;                                                                    \
  while (t--)

const ll INF = 1e18;
const ll N = 100005;
const ll MOD = 1e9 + 7;

int main() {
  fast
      // testcase
      //  {
      ll n;
  cin >> n;
  int a[n][3];

  loopi(i, n) {
    for (ll j = 0; j < 3; j++) {
      // debugh
      cin >> a[i][j];
    }
  }

  ll dp[n][3];
  dp[0][0] = a[0][0];
  dp[0][1] = a[0][1];
  dp[0][2] = a[0][2];

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

  ll ans = max(dp[n - 1][0], dp[n - 1][1]);
  ans = max(ans, dp[n - 1][2]);

  cout << ans << endl;

  // }

  return 0;
}