Language: C++

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define mod 1000000007
#define dd double
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
long dp[100001][4];
long a,b,c;
 
int knap(int arr[][3],int n,int a,int size){
	if(n==0)
		return 0;
	if(dp[n][a]!=-1)
		return dp[n][a];
	if(a == 0){
		a = arr[size-n][0] + knap(arr,n-1,1,size);
		b = arr[size-n][1] + knap(arr,n-1,2,size);
		c = arr[size-n][2] + knap(arr,n-1,3,size);
	}
	if(a == 1){
		a = -1;
		b = arr[size-n][1] + knap(arr,n-1,2,size);
		c = arr[size-n][2] + knap(arr,n-1,3,size);
	}
	if(a == 2){
		b = -1;
		a = arr[size-n][0] + knap(arr,n-1,1,size);
		c = arr[size-n][2] + knap(arr,n-1,3,size);
	}
	if(a == 3){
		c = -1;
		a = arr[size-n][0] + knap(arr,n-1,1,size);
		b = arr[size-n][1] + knap(arr,n-1,2,size);		
	}
	return dp[n][a] = max(max(a,b),c);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE    
    freopen("input.txt", "r", stdin);     
    freopen("output.txt", "w", stdout);
#endif
int n;
cin>>n;
int size = n;
int arr[n][3];
	rep(i,n){
		cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
	}
	// rep(i,n){
	// 	cout<<arr[i][0]<<arr[i][1]<<arr[i][2]<<endl;
	// }
	memset(dp,-1,sizeof(dp));
	cout<<knap(arr,n,0,size);
 
 
 
 
 
 
 
 
 
#ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
#endif
 
return 0;
}

Compiler output:
a.cc: In function 'int knap(int (*)[3], int, int, int)':
a.cc:42:34: error: no matching function for call to 'max(int&, long int&)'
   42 |         return dp[n][a] = max(max(a,b),c);
      |                               ~~~^~~~~
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:42:34: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long int')
   42 |         return dp[n][a] = max(max(a,b),c);
      |                               ~~~^~~~~
/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:42:34: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   42 |         return dp[n][a] = max(max(a,b),c);
      |                               ~~~^~~~~