Language: C++

#include "bits/stdc++.h"
#define LF '\n'
#define ALL(x) x.begin(), x.end()
#define iostreamBooster() { cin.tie(nullptr); ios_base::sync_with_stdio(false); }
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
template<class Itr> void dump(Itr begin, Itr end) { for (;begin != end; ++begin) clog << *begin << LF; }

int N;
i64 a[3005];
i64 dp[3005][3005];

i64 slv(int left, int right)
{
  if (left > right) { return 0; }
  i64 &ret = dp[left][right];
  if(~ret) { return ret; }

  bool isTaro = ((left + (N-1 - right)) % 2 == 0);

  if (isTaro) {
    ret = max(
        slv(left+1, right) + a[left],
        slv(left, right-1) + a[right]
    );
  }
  else {
    ret = min(
        slv(left+1, right) - a[left],
        slv(left, right-1) - a[right]
    );
  }
  return ret;
}

signed main()
{
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }

  memset(dp, -1, sizeof(dp));
  cout << slv(0, N-1) << endl;

  return 0;
}

#include "bits/stdc++.h"
#define LF '\n'
#define ALL(x) x.begin(), x.end()
#define iostreamBooster() { cin.tie(nullptr); ios_base::sync_with_stdio(false); }
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
template<class Itr> void dump(Itr begin, Itr end) { for (;begin != end; ++begin) clog << *begin << LF; }

int N;
i64 a[3005];
i64 dp[3005][3005];

i64 slv(int left, int right)
{
  if (left > right) { return 0; }
  i64 &ret = dp[left][right];
  if(~ret) { return ret; }

  bool isTaro = ((left + (N-1 - right)) % 2 == 0);

  if (isTaro) {
    ret = max(
        slv(left+1, right) + a[left],
        slv(left, right-1) + a[right]
    );
  }
  else {
    ret = min(
        slv(left+1, right) - a[left],
        slv(left, right-1) - a[right]
    );
  }
  return ret;
}

signed main()
{
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }

  memset(dp, -1, sizeof(dp));
  cout << slv(0, N-1) << endl;

  return 0;
}



Compiler output:
a.cc:60:39: error: redefinition of 'template<class A, class B> bool chmax(A&, const B&)'
   60 | template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
      |                                       ^~~~~
a.cc:8:39: note: 'template<class A, class B> bool chmax(A&, const B&)' previously declared here
    8 | template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
      |                                       ^~~~~
a.cc:61:39: error: redefinition of 'template<class A, class B> bool chmin(A&, const B&)'
   61 | template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
      |                                       ^~~~~
a.cc:9:39: note: 'template<class A, class B> bool chmin(A&, const B&)' previously declared here
    9 | template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
      |                                       ^~~~~
a.cc:62:15: error: redefinition of 'constexpr const int INF'
   62 | constexpr int INF = 0x3f3f3f3f;
      |               ^~~
a.cc:10:15: note: 'constexpr const int INF' previously defined here
   10 | constexpr int INF = 0x3f3f3f3f;
      |               ^~~
a.cc:63:26: error: redefinition of 'template<class Itr> void dump(Itr, Itr)'
   63 | template<class Itr> void dump(Itr begin, Itr end) { for (;begin != end; ++begin) clog << *begin << LF; }
      |                          ^~~~
a.cc:11:26: note: 'template<class Itr> void dump(Itr, Itr)' previously declared here
   11 | template<class Itr> void dump(Itr begin, Itr end) { for (;begin != end; ++begin) clog << *begin << LF; }
      |                          ^~~~
a.cc:65:5: error: redefinition of 'int N'
   65 | int N;
      |     ^
a.cc:13:5: note: 'int N' previously declared here
   13 | int N;
      |     ^
a.cc:66:5: error: redefinition of 'i64 a [3005]'
   66 | i64 a[3005];
      |     ^
a.cc:14:5: note: 'i64 a [3005]' previously declared here
   14 | i64 a[3005];
      |     ^
a.cc:67:5: error: redefinition of 'i64 dp [3005][3005]'
   67 | i64 dp[3005][3005];
      |     ^~
a.cc:15:5: note: 'i64 dp [3005][3005]' previously declared here
   15 | i64 dp[3005][3005];
      |     ^~
a.cc:69:5: error: redefinition of 'i64 slv(int, int)'
   69 | i64 slv(int left, int right)
      |     ^~~
a.cc:17:5: note: 'i64 slv(int, int)' previously defined here
   17 | i64 slv(int left, int right)
      |     ^~~
a.cc:92:8: error: redefinition of 'int main()'
   92 | signed main()
      |        ^~~~
a.cc:40:8: note: 'int main()' previously defined here
   40 | signed main()
      |        ^~~~