Language: C++

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using vi=vector<int>;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int r,c,k;
    cin >> r >> c >> k;
    vector<tuple<int,int,int>> p;
    rep(i,k){
        int x,y,z;
        cin >> x >> y >> z;
        --x; --y;
        p.push_back({x,y,z});
    }
    sort(p.begin(),p.end());
    ll dp[r+5][c+5]
    int cnt[r+5][c+5];
    rep(i,r){
        rep(j,c){
            dp[i][j]=0;
            cnt[i][j]=0;
        }
    }
    int s=0;
    vector<vector<int>> mini(r); 
    rep(i,r){
        int x,y,z;
        tie(x,y,z) = p[s];
        rep(j,c){
            if(i!=0 && j!=0){
                if(dp[i][j-1]<=dp[i-1][j]){
                    dp[i][j]=dp[i-1][j];
                    cnt[i][j]=0;
                    fill(mini[i].begin(),mini[i].end(),0);
                }else{
                    dp[i][j]=dp[i][j-1];
                    cnt[i][j]=cnt[i][j-1];
                }
            }
            else if(i==0 && j!=0){
                dp[i][j]=dp[i][j-1];
                cnt[i][j]=cnt[i][j-1];
            }
            else if(i!=0 && j==0){
                dp[i][j]=dp[i-1][j];
                cnt[i][j]=0;
                fill(mini[i].begin(),mini[i].end(),0);
            }
            if(i==x && j==y){
                if(cnt[i][j]<3){
                    dp[i][j]+=z;
                    ++cnt[i][j];
                    mini[i].push_back(z);
                    sort(mini[i].begin(),mini[i].end());
                }else{
                    if(z>mini[i][0]){
                        dp[i][j]-=mini[i][0];
                        dp[i][j]+=z;
                        mini[i][0]=z;
                        sort(mini[i].begin(),mini[i].end());
                    }
                }
                ++s;
                tie(x,y,z)=p[s];
            }
        }
    }
    cout << dp[r-1][c-1] << "\n";
    return 0;
}   

Compiler output:
a.cc: In function 'int main()':
a.cc:24:5: error: expected initializer before 'int'
   24 |     int cnt[r+5][c+5];
      |     ^~~
a.cc:27:13: error: 'dp' was not declared in this scope; did you mean 'p'?
   27 |             dp[i][j]=0;
      |             ^~
      |             p
a.cc:28:13: error: 'cnt' was not declared in this scope; did you mean 'int'?
   28 |             cnt[i][j]=0;
      |             ^~~
      |             int
a.cc:38:20: error: 'dp' was not declared in this scope; did you mean 'p'?
   38 |                 if(dp[i][j-1]<=dp[i-1][j]){
      |                    ^~
      |                    p
a.cc:40:21: error: 'cnt' was not declared in this scope; did you mean 'int'?
   40 |                     cnt[i][j]=0;
      |                     ^~~
      |                     int
a.cc:44:21: error: 'cnt' was not declared in this scope; did you mean 'int'?
   44 |                     cnt[i][j]=cnt[i][j-1];
      |                     ^~~
      |                     int
a.cc:48:17: error: 'dp' was not declared in this scope; did you mean 'p'?
   48 |                 dp[i][j]=dp[i][j-1];
      |                 ^~
      |                 p
a.cc:49:17: error: 'cnt' was not declared in this scope; did you mean 'int'?
   49 |                 cnt[i][j]=cnt[i][j-1];
      |                 ^~~
      |                 int
a.cc:52:17: error: 'dp' was not declared in this scope; did you mean 'p'?
   52 |                 dp[i][j]=dp[i-1][j];
      |                 ^~
      |                 p
a.cc:53:17: error: 'cnt' was not declared in this scope; did you mean 'int'?
   53 |                 cnt[i][j]=0;
      |                 ^~~
      |                 int
a.cc:57:20: error: 'cnt' was not declared in this scope; did you mean 'int'?
   57 |                 if(cnt[i][j]<3){
      |                    ^~~
      |                    int
a.cc:58:21: error: 'dp' was not declared in this scope; did you mean 'p'?
   58 |                     dp[i][j]+=z;
      |                     ^~
      |                     p
a.cc:64:25: error: 'dp' was not declared in this scope; did you mean 'p'?
   64 |                         dp[i][j]-=mini[i][0];
      |                         ^~
      |                         p
a.cc:75:13: error: 'dp' was not declared in this scope; did you mean 'p'?
   75 |     cout << dp[r-1][c-1] << "\n";
      |             ^~
      |             p