Language: C++

#include<bits/stdc++.h>
#define f(i,n) for(int i=0;i<n;i++)
#define fo(i,a,n) for(int i=a;i<n;i++)
#define ll long long int
#define li long int
using namespace std;
int n;
vector<int> a(100005);
vector<int> b(100005);
vector<int> c(100005);
vector<vector<ll>> dp(100005,vector<ll> (4,-1));
int cost(int ind,int parent)
{
    if(ind==n-1)
    {
        if(parent==1)
            return a[ind];
        else if(parent==1)
            return b[ind];
        else
            return c[ind];
    }
    if(dp[ind][parent]==-1)
    {
        if(parent==1)
        {
            dp[ind][parent]=a[ind]+max(cost(ind+1,2),cost(ind+1,3));
            //return dp[ind][parent];
        }
        else if(parent==2)
        {
            dp[ind][parent]=b[ind]+max(cost(ind+1,1),cost(ind+1,3));
            //return dp2[ind];
        }
        else
        {
            dp[ind][parent]=c[ind]+max(cost(ind+1,2),cost(ind+1,1));
            //return dp3[ind];
        }
    }
    return dp[ind][parent];

}
int main()
{
    cin>>n;
    f(i,n)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    ll ans=max(cost(0,1),cost(0,2));
    ll ans=max(ans,cost(0,3))
    cout<<ans;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:52:8: error: redeclaration of 'long long int ans'
   52 |     ll ans=max(ans,cost(0,3))
      |        ^~~
a.cc:51:8: note: 'long long int ans' previously declared here
   51 |     ll ans=max(cost(0,1),cost(0,2));
      |        ^~~
a.cc:52:15: error: no matching function for call to 'max(long long int&, int)'
   52 |     ll ans=max(ans,cost(0,3))
      |            ~~~^~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:52:15: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   52 |     ll ans=max(ans,cost(0,3))
      |            ~~~^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:52:15: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   52 |     ll ans=max(ans,cost(0,3))
      |            ~~~^~~~~~~~~~~~~~~