Language: C++

#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define all(n) (n).begin(),(n).end()
#define fi first
#define se second

typedef pair<int, int> PII;
typedef long long ll;

const int MOD = 1e9+7;

int main() {

	ios::sync_with_stdio(0);
	cin.tie(0);

	int r,c,k;
	cin >> r >> c >> k;
	ll gr[3001][3001];
	memset(gr,0,sizeof(gr));
	for (int i = 0; i < k; i++) {
		int a,b,v;
		cin >> a >> b >> v;
		gr[a][b]=v;
	}
	ll dp[3005][3005][4];
	memset(dp,0,sizeof(dp));
	for (int i = r; i; i--) {
		for (int j = c; j; j--) {
			dp[i][j][0]=max({dp[i][j+1][0],gr[i][j],gr[i][j]+max({dp[i+1][j][0],dp[i+1][j][1],dp[i+1][j][2]})});
			dp[i][j][1]=max(dp[i][j+1][1],gr[i][j]+dp[i][j+1][0]);
			dp[i][j][2]=max(dp[i][j+1][2],gr[i][j]+dp[i][j+1][1]);
			// cout << dp[i][j][0] << " " << dp[i][j][1] << " " << dp[i][j][2] << " " << dp[i][j][3] << "\n";
		}
	}
	int ans = 0;
	for (int i = 0; i < 4; i++) ans = max(ans,dp[1][1][i]);
	cout << ans << "\n";
}

Compiler output:
a.cc: In function 'int main()':
a.cc:40:46: error: no matching function for call to 'max(int&, ll&)'
   40 |         for (int i = 0; i < 4; i++) ans = max(ans,dp[1][1][i]);
      |                                           ~~~^~~~~~~~~~~~~~~~~
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:40:46: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   40 |         for (int i = 0; i < 4; i++) ans = max(ans,dp[1][1][i]);
      |                                           ~~~^~~~~~~~~~~~~~~~~
/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:40:46: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   40 |         for (int i = 0; i < 4; i++) ans = max(ans,dp[1][1][i]);
      |                                           ~~~^~~~~~~~~~~~~~~~~