Language: C++

#include <bits/stdc++.h>
#include <set>
#include <queue>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++) 
#define reps(i, s, n) for (int i = s; i < (int)(n); i++) 
#define ll long long
#define ld long double
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++) 
#define repsl(i, s, n) for (ll i = s; i < (ll)(n); i++)  
#define outdeb(fir, sec, thr) cout << fir << ":" << sec << ":" << thr << endl

#define lpair pair<ll, ll>
#define llvecvec vector<vector<vector<ll>>>
#define INF 3000000000

ll item[3001][3001];
ll data[3001][3001][4];

ll getMax(ll r, ll c)
{
  ll maxv = 0;
  rep(i, 4)
  {
    maxv = max(maxv, data[r][c][i]);
  }

  return maxv;
}

int main()
{
  ll r,c,k;
  cin >> r >> c >> k;

  repl(i, r)
  {
    repl(j, c)
    {
      item[i][j] = 0;
      repl(k , 4)
      {
        data[i][j][k] = -INF;
      }
    }
  }
  
  repl(i, k)
  {
    ll a,b,c;
    cin >> a >> b >> c;
    item[a-1][b-1] = c;
  }

  repl(i, r)
  repl(j, c)
  repl(k, 4)
  {
    if(i == 0 && j == 0)
    {
      if(k == 1 && item[i][j] > 0)
      {
        data[i][j][k] = item[i][j];
      }
      else if(k == 0)
      {
        data[i][j][k] = 0;
      }
      else
      {
        data[i][j][k] = -INF;
      } 
    }
    else if(j == 0)
    {
      if(k == 1 && item[i][j] > 0)
      {
        data[i][j][k] = getMax(i-1, j) + item[i][j];
      }
      else if(k == 0)
      {
        data[i][j][k] = getMax(i-1, j);
      }
      else
      {
        data[i][j][k] = -INF;
      }
    }
    else if(i == 0)
    {
      if(k == 0)
      {
        data[i][j][k] = 0;
        continue;
      }

      ll tmp = -INF;
      if(data[i][j-1][k-1] >= 0 && item[i][j] > 0)
      {
        tmp = data[i][j-1][k-1] + item[i][j];
      }
      
      data[i][j][k] = max(data[i][j-1][k], tmp);
    }
    else
    {
      ll tmp = -INF;
      if(k > 0 && data[i][j-1][k-1] >= 0 && item[i][j] > 0)
      {
        tmp = data[i][j-1][k-1] + item[i][j];
      }
      tmp = max(tmp, data[i][j-1][k]);
      if(k == 1 && item[i][j] > 0)
      {
        tmp = max(tmp, getMax(i-1, j) + item[i][j]);
      }
      else if(k == 0)
      {
        tmp = max(tmp, getMax(i-1, j));
      }
      data[i][j][k] = tmp;
    }
  }

  cout << fixed << getMax(r-1, c-1) << endl;

  return 0;
}

Compiler output:
a.cc: In function 'long long int getMax(long long int, long long int)':
a.cc:27:22: error: reference to 'data' is ambiguous
   27 |     maxv = max(maxv, data[r][c][i]);
      |                      ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:20:4: note:                 'long long int data [3001][3001][4]'
   20 | ll data[3001][3001][4];
      |    ^~~~
a.cc: In function 'int main()':
a.cc:45:9: error: reference to 'data' is ambiguous
   45 |         data[i][j][k] = -INF;
      |         ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:20:4: note:                 'long long int data [3001][3001][4]'
   20 | ll data[3001][3001][4];
      |    ^~~~
a.cc:65:9: error: reference to 'data' is ambiguous
   65 |         data[i][j][k] = item[i][j];
      |         ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:20:4: note:                 'long long int data [3001][3001][4]'
   20 | ll data[3001][3001][4];
      |    ^~~~
a.cc:69:9: error: reference to 'data' is ambiguous
   69 |         data[i][j][k] = 0;
      |         ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:20:4: note:                 'long long int data [3001][3001][4]'
   20 | ll data[3001][3001][4];
      |    ^~~~
a.cc:73:9: error: reference to 'data' is ambiguous
   73 |         data[i][j][k] = -INF;
      |         ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:20:4: note:                 'long long int data [3001][3001][4]'
   20 | ll data[3001][3001][4];
      |    ^~~~
a.cc:80:9: error: reference to 'data' is ambiguous
   80 |         data[i][j][k] = getMax(i-1, j) + item[i][j];
      |         ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:20:4: note:                 'long long int data [3001][3001][4]'
   20 | ll data[3001][3001][4];
      |    ^~~~
a.cc:84:9: error: reference to 'data' is ambiguous
   84 |         data[i][j][k] = getMax(i-1, j);
      |         ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:20:4: note:                 'long long int data [3001][3001][4]'
   20 | ll data[3001][3001][4];
      |    ^~~~
a.cc:88:9: error: reference to 'data' is ambiguous
   88 |         data[i][j][k] = -INF;
      |         ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:20:4: note:                 'long long int data [3001][3001][4]'
   20 | ll data[3001][3001][4];
      |    ^~~~
a.cc:95:9: error: reference to 'data' is ambiguous
   95 |         data[i][j][k] = 0;
      |         ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h