Problem p03162 (C++)

Buggy submission (status: Runtime Error):
/*
Competitive programming template
Author: Aswin Sampath

*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef priority_queue<ll, vl, greater<ll>()> pq_ll_min;
typedef priority_queue<ll> pq_ll_max;
typedef stack<ll> s;
typedef queue<ll> q;

#define pi 3.141592653589793
#define PI acos(-1.0)
#define space " "
#define endl '\n'
#define F first
#define S second
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a, b)

#define FAST                                                                   \
  {                                                                            \
    ios_base::sync_with_stdio(false);                                          \
    cin.tie(0);                                                                \
    cout.tie(0);                                                               \
  }
#define testcase                                                               \
  ll t;                                                                        \
  cin >> t;                                                                    \
  while (t--)
#define dbxstl(x)                                                              \
  {                                                                            \
    for (auto ele : x)                                                         \
      cout << ele << space;                                                    \
    cout << endl;                                                              \
  }
#define dbxval(x)                                                              \
  { cout << x << endl; }

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

void solve() { printf("Hello\n"); }

int main(int argc, char const *argv[]) {
  ll n;
  cin >> n;
  vector<ll> dp(3, 0);
  for (int days = 0; days < n; days++) {
    vector<ll> temp(3, 0);
    vector<ll> params(3);

    for (int i = 0; i < 3; i++) {
      cin >> params[i];
    }

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < 3; j++) {
        if (i != j) {
          temp[j] = max(temp[j], dp[i] + params[j]);
        }
      }
    }
    dp = temp;
  }
  ll ans = max({dp[0], dp[1], dp[2]});
  cout << ans << endl;

  return 0;
}


Fixed submission:
/*
Competitive programming template
Author: Aswin Sampath

*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef priority_queue<ll, vl, greater<ll>()> pq_ll_min;
typedef priority_queue<ll> pq_ll_max;
typedef stack<ll> s;
typedef queue<ll> q;

#define pi 3.141592653589793
#define PI acos(-1.0)
#define space " "
#define endl '\n'
#define F first
#define S second
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a, b)

#define FAST                                                                   \
  {                                                                            \
    ios_base::sync_with_stdio(false);                                          \
    cin.tie(0);                                                                \
    cout.tie(0);                                                               \
  }
#define testcase                                                               \
  ll t;                                                                        \
  cin >> t;                                                                    \
  while (t--)
#define dbxstl(x)                                                              \
  {                                                                            \
    for (auto ele : x)                                                         \
      cout << ele << space;                                                    \
    cout << endl;                                                              \
  }
#define dbxval(x)                                                              \
  { cout << x << endl; }

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

void solve() { printf("Hello\n"); }

int main(int argc, char const *argv[]) {
  ll n;
  cin >> n;
  vector<ll> dp(3, 0);
  for (int days = 0; days < n; days++) {
    vector<ll> temp(3, 0);
    vector<ll> params(3);

    for (int i = 0; i < 3; i++) {
      cin >> params[i];
    }

    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        if (i != j) {
          temp[j] = max(temp[j], dp[i] + params[j]);
        }
      }
    }
    dp = temp;
  }
  ll ans = max({dp[0], dp[1], dp[2]});
  cout << ans << endl;

  return 0;
}