Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a)  (a).begin(),(a).end()
const ll INF = 1e18+18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;



int main(){
  ll R, C, K;
  cin>>R>>C>>K;
  vector<ll> RR(K), CC(K), VV(K);
  vector<vector<ll>> Check(R, vector<ll>(C, 0));
  rep(i, K){
    cin>>RR[i]>>CC[i]>>VV[i];
    RR[i]--; CC[i]--;
    Check[RR[i]][CC[i]]=VV[i];
  }
  ll dp[3010][3010][4];
  rep(i, R+1){
    rep(j, C+1){
      rep(k, 4){
       	dp[i][j][k]=-1*INF;
      }
    }
  }
  /*rep(i, R){
rep(j, C){
  cout<<Check[i][j]<<" ";
}
  cout<<endl;}**/
  
  dp[0][0][0]=0;
  if(Check[0][0]>0)dp[0][0][1]=Check[0][0];
  
  rep(i, R){
    rep(j, C){
      
      if(i>0){
        dp[i][j][0]=max(dp[i][j][0],dp[i-1][j][0]);
        dp[i][j][0]=max(dp[i][j][0],dp[i-1][j][1]);
        dp[i][j][0]=max(dp[i][j][0],dp[i-1][j][2]);
        dp[i][j][0]=max(dp[i][j][0],dp[i-1][j][3]);
        if(Check[i][j]>0){
          dp[i][j][1]=max(dp[i][j][1], dp[i-1][j][0]+Check[i][j]);
          dp[i][j][1]=max(dp[i][j][1], dp[i-1][j][1]+Check[i][j]);
          dp[i][j][1]=max(dp[i][j][1], dp[i-1][j][2]+Check[i][j]);
          dp[i][j][1]=max(dp[i][j][1], dp[i-1][j][3]+Check[i][j]);
        }
      }
      if(j>0){
        dp[i][j][0]=max(dp[i][j][0], dp[i][j-1][0]);
        dp[i][j][1]=max(dp[i][j][1], dp[i][j-1][1]);
        dp[i][j][2]=max(dp[i][j][2], dp[i][j-1][2]);
        dp[i][j][3]=max(dp[i][j][3], dp[i][j-1][3]);
        if(Check[i][j]>0){
          dp[i][j][1]=max(dp[i][j][1], dp[i][j-1][0]+Check[i][j]);
          dp[i][j][2]=max(dp[i][j][2], dp[i][j-1][1]+Check[i][j]);
          dp[i][j][3]=max(dp[i][j][3], dp[i][j-1][2]+Check[i][j]);
        }
      }
      //cout<<i<<" "<<j<<"   "<<dp[i][j][0]<<" "<<dp[i][j][1]<<" "<<dp[i][j][2]<<" "<<dp[i][j][3]<<endl;
    }
  }
  
  ll Ans=max(dp[R-1][C-1][0], dp[R-1][C-1][1]);
  //ll Anss=max(dp[R-1][C-1][2], dp[R-1][C-1][3]);
  
  cout<<max(Ans)<<endl;
  return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:77:12: error: no matching function for call to 'max(ll&)'
   77 |   cout<<max(Ans)<<endl;
      |         ~~~^~~~~
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:   candidate expects 2 arguments, 1 provided
/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, 1 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:   template argument deduction/substitution failed:
a.cc:77:12: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   77 |   cout<<max(Ans)<<endl;
      |         ~~~^~~~~
/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:   candidate expects 2 arguments, 1 provided