Language: C++

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int main()
{
  int R, C, K;
  cin >> R >> C >> K;

  vector<vector<vector<ll>>> A(R, vector<vector<ll>>(C, vector<ll>(4, -1)));

  vector<vector<ll>> Vs(R, vector<ll>(C, 0));

  for (int i = 0; i < K; i++)
  {

    int r, c, v;
    cin >> r >> c >> v;

    Vs[r - 1][c - 1] = v;
  }

  if (Vs[0][0] == 0)
  {
    A[0][0][0] = 0;
  }
  else
  {

    A[0][0][1] = Vs[0][0];
  }

  if (C > 1)
  {
    for (int i = 0; i < (C - 1); i++)
    {

      A[0][i + 1][0] = 0;

      for (int k = 1; k < 4; k++)
      {

        if (Vs[0][i + 1] > 0 && A[0][i][k - 1] != -1)
        {

          A[0][i + 1][k] = max(A[0][i][k - 1] + Vs[0][i + 1], A[0][i][k]);
        }
        else
        {

          A[0][i + 1][k] = A[0][i][k];
        }
      }
    }
  }

  if (R > 1)
  {
    for (int j = 0; j < (R - 1); j++)
    {

      ll art0 = max(A[j][0][0], A[j][i + 1][1]);
      if (Vs[0][0] == 0)
      {
        A[j + 1][0][0] = art0;
      }
      else
      {

        A[j + 1][0][1] = art0 + Vs[j + 1][0];
      }

      if (C > 1)
      {

        for (int i = 0; i < (C - 1); i++)
        {

          ll art = max(A[j][i + 1][0], A[j][i + 1][1]);
          art = max(A[j][i + 1][2], art);
          art = max(A[j][i + 1][3], art);

          A[j + 1][i + 1][0] = max(A[j + 1][i][0], art);

          for (int k = 1; k < 4; k++)
          {

            if (Vs[j + 1][i + 1] > 0 && A[j + 1][i][k - 1] != -1)
            {

              A[j + 1][i + 1][k] = max(A[j + 1][i][k - 1] + Vs[j + 1][i + 1], A[j + 1][i][k]);

              if (k == 1)
              {

                A[j + 1][i + 1][k] = max(art + Vs[j + 1][i + 1], A[j + 1][i + 1][k]);
              }
            }
            else
            {

              A[j + 1][i + 1][k] = A[j + 1][i][k];
            }
          }
        }
      }
    }
  }
}
}

ll ans = max(A[R - 1][C - 1][0], A[R - 1][C - 1][1]);
ans = max(A[R - 1][C - 1][2], ans);
ans = max(A[R - 1][C - 1][3], ans);

cout << ans << endl;
return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:63:38: error: 'i' was not declared in this scope
   63 |       ll art0 = max(A[j][0][0], A[j][i + 1][1]);
      |                                      ^
a.cc: At global scope:
a.cc:111:1: error: expected declaration before '}' token
  111 | }
      | ^
a.cc:113:14: error: 'A' was not declared in this scope
  113 | ll ans = max(A[R - 1][C - 1][0], A[R - 1][C - 1][1]);
      |              ^
a.cc:113:16: error: 'R' was not declared in this scope
  113 | ll ans = max(A[R - 1][C - 1][0], A[R - 1][C - 1][1]);
      |                ^
a.cc:113:23: error: 'C' was not declared in this scope
  113 | ll ans = max(A[R - 1][C - 1][0], A[R - 1][C - 1][1]);
      |                       ^
a.cc:113:34: error: 'A' was not declared in this scope
  113 | ll ans = max(A[R - 1][C - 1][0], A[R - 1][C - 1][1]);
      |                                  ^
a.cc:113:36: error: 'R' was not declared in this scope
  113 | ll ans = max(A[R - 1][C - 1][0], A[R - 1][C - 1][1]);
      |                                    ^
a.cc:113:43: error: 'C' was not declared in this scope
  113 | ll ans = max(A[R - 1][C - 1][0], A[R - 1][C - 1][1]);
      |                                           ^
a.cc:114:1: error: 'ans' does not name a type
  114 | ans = max(A[R - 1][C - 1][2], ans);
      | ^~~
a.cc:115:1: error: 'ans' does not name a type
  115 | ans = max(A[R - 1][C - 1][3], ans);
      | ^~~
a.cc:117:1: error: 'cout' does not name a type
  117 | cout << ans << endl;
      | ^~~~
a.cc:118:1: error: expected unqualified-id before 'return'
  118 | return 0;
      | ^~~~~~
a.cc:119:1: error: expected declaration before '}' token
  119 | }
      | ^