Problem p03162 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define f0(i, n) for (long long int i = 0; i < n; i++)
#define f1(i, n) for (long long int i = 1; i <= n; i++)
#define f2(i, a, b) for (long long int i = a; i <= b; i++)
#define sp << " "      // giving space
#define sp1 << " " <<  // giving space between two elements
#define nl << "/n"     // new line
#define MOD 1000000007 // for mod
#define ll long long
#define ld long double
using namespace std;
// Vector
#define vi vector<int>                  // integer vector
#define vll vector<long long>           // long long vector
#define pb(v, i) v.push_back(i)         // vector element insertion
#define er(v, i) v.erase(v.begin() + i) // erase ith element in a vector
#define erng(v, x) v.erase(v.begin(), v.begin() + x) // delete a range in array
#define av(first, last, sum) accumulate(first, last, sum) // sum of vector
#define vmax(v, x) *max_element(v, v + x)        // max element in vector
#define vmin(v, x) *min_element(v, v + x)        // min element in vector
#define sv(v) sort(v.begin(), v.end())           // sort complete vector
#define svx(v, x) sort(v.begin(), v.begin() + x) // sort partial vector
#define low(v, x)                                                              \
  *lower_bound(v.begin(), v.end(), x) // lower bound of a number in vector
#define up(v, x)                                                               \
  *upper_bound(v.begin(), v.end(), x) // upper bound of a number in vector

// Stack
/*  stack<int> s;                       //declaring stack
s.push(1)                       // enter  element in stack
s.top()                         //returns top element in stack
s.pop()                         //removes top element in  stack
*/
// pair
#define pii pair<int, int> // pair integers
#define F first
#define S second
#define mp(a, b)                                                               \
  make_pair(a, b) // entering pair element in vector(size not defined)

// Hashmap
/* map<string,string> a;                //declaration
a[“abc”]=”xyz”;                 // element entry in map;
gquiz1.insert(pair<int, int>(1, 40));
map<string,string>::iterator itr;           //iterating map
for (itr = a.begin(); itr!=a.end(); itr++){
    cout <<(*itr).first  << itr->second <<endl;
  }
  itr = companies.find("abc");      //finding element in map
  cout << itz->second;

//*/

// FUNCTION TO FIND PRIME
/*bool is_prime(int p){
    for(int i = 2; i*i <= p; i++){
        if(p % i == 0) return false;
    }
    return true;
}
*/
/*                                           //DSU by path compression using
size int parent[100005]; int siz[100005]; bool vis[100005];

int find_set(int v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}

void make_set(int v) {
    parent[v] = v;
    siz[v] = 1;
    vis[v]=1;
}

void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (siz[a] < siz[b])
            swap(a, b);
        parent[b] = a;
        siz[a] += siz[b];
    }
}

*/
/*                                                    // DFS FUNCTION
vector<int> graph[100005];
bool vis[100005];

void add_edge(int u,int v){
        pb(graph[u],v);
        pb(graph[v],u);
}

void dfs(int i)
{
    vis[i]=1;

    for(auto j : graph[i])
    {
        if(!vis[j])
            dfs(j);
    }
}
*/

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  ll n, d, e, f;
  cin >> n;

  vector<ll> a(n), b(n), c(n);

  f0(i, n) cin >> a[i] >> b[i] >> c[i];

  f0(i, n) {
    d = a[i];
    e = b[i];
    f = c[i];

    if (i == n - 1)
      break;

    a[i + 1] = max(e + a[i + 1], f + a[i + 1]);
    b[i + 1] = max(d + b[i + 1], f + b[i + 1]);
    c[i + 1] = max(d + c[i + 1], e + c[i + 1]);
  }

  cout << max(d, max(e, f));

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define f0(i, n) for (long long int i = 0; i < n; i++)
#define f1(i, n) for (long long int i = 1; i <= n; i++)
#define f2(i, a, b) for (long long int i = a; i <= b; i++)
#define sp << " "      // giving space
#define sp1 << " " <<  // giving space between two elements
#define nl << "/n"     // new line
#define MOD 1000000007 // for mod
#define ll long long
#define ld long double
using namespace std;
// Vector
#define vi vector<int>                  // integer vector
#define vll vector<long long>           // long long vector
#define pb(v, i) v.push_back(i)         // vector element insertion
#define er(v, i) v.erase(v.begin() + i) // erase ith element in a vector
#define erng(v, x) v.erase(v.begin(), v.begin() + x) // delete a range in array
#define av(first, last, sum) accumulate(first, last, sum) // sum of vector
#define vmax(v, x) *max_element(v, v + x)        // max element in vector
#define vmin(v, x) *min_element(v, v + x)        // min element in vector
#define sv(v) sort(v.begin(), v.end())           // sort complete vector
#define svx(v, x) sort(v.begin(), v.begin() + x) // sort partial vector
#define low(v, x)                                                              \
  *lower_bound(v.begin(), v.end(), x) // lower bound of a number in vector
#define up(v, x)                                                               \
  *upper_bound(v.begin(), v.end(), x) // upper bound of a number in vector

// Stack
/*  stack<int> s;                       //declaring stack
s.push(1)                       // enter  element in stack
s.top()                         //returns top element in stack
s.pop()                         //removes top element in  stack
*/
// pair
#define pii pair<int, int> // pair integers
#define F first
#define S second
#define mp(a, b)                                                               \
  make_pair(a, b) // entering pair element in vector(size not defined)

// Hashmap
/* map<string,string> a;                //declaration
a[“abc”]=”xyz”;                 // element entry in map;
gquiz1.insert(pair<int, int>(1, 40));
map<string,string>::iterator itr;           //iterating map
for (itr = a.begin(); itr!=a.end(); itr++){
    cout <<(*itr).first  << itr->second <<endl;
  }
  itr = companies.find("abc");      //finding element in map
  cout << itz->second;

//*/

// FUNCTION TO FIND PRIME
/*bool is_prime(int p){
    for(int i = 2; i*i <= p; i++){
        if(p % i == 0) return false;
    }
    return true;
}
*/
/*                                           //DSU by path compression using
size int parent[100005]; int siz[100005]; bool vis[100005];

int find_set(int v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}

void make_set(int v) {
    parent[v] = v;
    siz[v] = 1;
    vis[v]=1;
}

void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (siz[a] < siz[b])
            swap(a, b);
        parent[b] = a;
        siz[a] += siz[b];
    }
}

*/
/*                                                    // DFS FUNCTION
vector<int> graph[100005];
bool vis[100005];

void add_edge(int u,int v){
        pb(graph[u],v);
        pb(graph[v],u);
}

void dfs(int i)
{
    vis[i]=1;

    for(auto j : graph[i])
    {
        if(!vis[j])
            dfs(j);
    }
}
*/

int main() {

  ll n, d, e, f;
  cin >> n;

  vector<ll> a(n), b(n), c(n);

  f0(i, n) cin >> a[i] >> b[i] >> c[i];

  f0(i, n) {
    d = a[i];
    e = b[i];
    f = c[i];

    if (i == n - 1)
      break;

    a[i + 1] = max(e + a[i + 1], f + a[i + 1]);
    b[i + 1] = max(d + b[i + 1], f + b[i + 1]);
    c[i + 1] = max(d + c[i + 1], e + c[i + 1]);
  }

  cout << max(d, max(e, f));

  return 0;
}