Language: C++

// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")

#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define clr clear()
#define ins insert
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define rep(i,n) for(__typeof(n) i=0; i<(n); i++)
#define mem(x,val) memset((x),(val),sizeof(x));
#define cusmem(x,val) for(auto &i:x) i=val;
#define all(x) x.begin(),x.end()
#define fastio ios_base::sync_with_stdio(false);\
            cin.tie(NULL);\
            cout.tie(NULL);
using namespace std;
typedef pair<int,int> pii;
typedef pair<ll,ll>pll;
typedef pair<ll,int>pli;
typedef vector<ll> vl;
typedef vector<pll> vpll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<pii> vpii;
string impossible;

mt19937 mt_rand(chrono::high_resolution_clock::now().time_since_epoch().count());

// const int N=6;
const int N=5e2+5;
const int M=1e4+5;
const int L=41;
int MOD=1e9+7;
// ll n,m,k,i,j,d;
bool f0,f1,f2;
const int MAXN=2e3;
int main(){
    #ifndef ONLINE_JUDGE
            freopen("input.txt","r",stdin); 
            freopen("output.txt","w",stdout);
    #endif
    fastio
    cout<<fixed<<setprecision(11);
    int tests=1;    
    // cin>>tests;
    for(int te=1;te<=tests;te++){
        ll r,c,items;  cin>>r>>c>>items;
        int v[r][c]; mem(v,0);
        for(int i=0;i<items;i++){
            int x,y,val;    cin>>x>>y>>val;
            v[x-1][y-1]=val;
        }
        ll dp[r][c][4];
        mem(dp,0);
        for(int i=0;i<r;i++){
            for(int j=0;j<c;j++){
                for(int k=0;k<4;k++){
                    if(i-1>=0)  dp[i][j][k]=max(dp[i-1][j][3],dp[i][j][k]);
                    if(j-1>=0)  dp[i][j][k]=max(dp[i][j-1][k],dp[i][j][k]);
                    if(k>0){
                        if(i-1>=0)  dp[i][j][k]=max(v[i][j]+dp[i-1][j][3],dp[i][j][k]);
                        if(j-1>=0)  dp[i][j][k]=max(v[i][j]+dp[i][j-1][k-1],dp[i][j][k]);
                        dp[i][j][k]=max(dp[i][j][k],v[i][j]);
                    }
                    // cout<<dp[i][j][k]<<" ";
                }
                // cout<<"|\t|";
            }
            // cout<<"\n";
        }
        cout<<dp[r-1][c-1][3];
    }
    return 0;
}





Compiler output:
a.cc: In function 'int main()':
a.cc:69:40: error: no matching function for call to 'max(long long int&, int&)'
   69 |                         dp[i][j][k]=max(dp[i][j][k],v[i][j]);
      |                                     ~~~^~~~~~~~~~~~~~~~~~~~~
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:5:
/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:69:40: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   69 |                         dp[i][j][k]=max(dp[i][j][k],v[i][j]);
      |                                     ~~~^~~~~~~~~~~~~~~~~~~~~
/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:69:40: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   69 |                         dp[i][j][k]=max(dp[i][j][k],v[i][j]);
      |                                     ~~~^~~~~~~~~~~~~~~~~~~~~