Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define mp make_pair
// GCD inbuilt func: __gcd(a,b)
// LCM formula: (a*b)/__gcd(a,b)
 
int main(){
	ios::sync_with_stdio(false);
    cin.tie(NULL);
	// CODE goes here
    int r,c,items;
    cin >> r >> c >> items;
    int dp[r][c][4];
    for(int i=0;i<r;i++){
    	for(int j=0;j<c;j++){
    		for(int k=0;k<4;k++) dp[i][j][k]=0;
    	}
    }
    ll a[r][c];
    for(int i=0;i<r;i++)
        for(int j=0;j<c;j++) a[i][j]=0;
    while(items--){
    	ll i,j,v;
    	cin >> i >> j >> v;
    	a[i-1][j-1]=v;
    }
    if(r==1 && c==1){
        cout << a[r-1][c-1];
        return 0;
    }
    for(int i=0;i<r;i++){
    	for(int j=0;j<c;j++){
            for(int k=2;k>=0;k--){
                dp[i][j][k+1]=max(dp[i][j][k+1],dp[i][j][k]+a[i][j]);
            }
            for(int k=0;k<4;k++){
                if(j+1!=c) dp[i][j+1][k]=max(dp[i][j+1][k],dp[i][j][k]);
                if(i+1!=r) dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][k]);
            }
    	}
    }
    ll maxi=0;
    for(int i=0;i<r;i++){
    	for(int j=0;j<c;j++){
    		for(int k=0;k<4;k++){
    			maxi=max(maxi,dp[i][j][k]);
    		}
    	}
    }
    cout << maxi;
	return 0;
}


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