Language: C++



int main()
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  std::cin >> N;
  v.resize(N);
  dp = vector<vector<long long>>(N+1, vector<long long>(2, LIM));
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <limits>

using namespace std;

int N;
vector<long long> v;
vector<vector<long long>> dp;
long long LIM = std::numeric_limits<long long>::min();

long long deque(long long i, long long j, long long c = 1)
{
  if (i+1 == j) return v[i] * c;

  int k = c < 0 ? 0 : 1;

  if (dp[j-i][k] != LIM)
  {
    return dp[j-i][k];
  }

  long long a = v[i]*c + deque(i+1, j, c*-1);
  long long b = v[j-1]*c + deque(i, j-1, c*-1);

  dp[j-i][k] = c < 0 ? min(a, b) : max(a, b); 
  return dp[j-i][k];
}
  for (int i = 0; i < N; ++i)
  {
    long long val;
    cin >> val;
    v[i] = val;
  }

  std::cout << deque(0, N);

  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:5:8: error: 'std::ios_base' has not been declared
    5 |   std::ios_base::sync_with_stdio(false);
      |        ^~~~~~~~
a.cc:6:8: error: 'cin' is not a member of 'std'
    6 |   std::cin.tie(0);
      |        ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | 
a.cc:8:8: error: 'cin' is not a member of 'std'
    8 |   std::cin >> N;
      |        ^~~
a.cc:8:8: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:8:15: error: 'N' was not declared in this scope
    8 |   std::cin >> N;
      |               ^
a.cc:9:3: error: 'v' was not declared in this scope
    9 |   v.resize(N);
      |   ^
a.cc:10:3: error: 'dp' was not declared in this scope
   10 |   dp = vector<vector<long long>>(N+1, vector<long long>(2, LIM));
      |   ^~
a.cc:10:8: error: 'vector' was not declared in this scope
   10 |   dp = vector<vector<long long>>(N+1, vector<long long>(2, LIM));
      |        ^~~~~~
a.cc:10:22: error: expected primary-expression before 'long'
   10 |   dp = vector<vector<long long>>(N+1, vector<long long>(2, LIM));
      |                      ^~~~
In file included from /usr/include/c++/14/bits/requires_hosted.h:31,
                 from /usr/include/c++/14/iostream:38,
                 from a.cc:11:
/usr/include/x86_64-linux-gnu/c++/14/bits/c++config.h:308:1: error: 'namespace' definition is not allowed here
  308 | namespace std
      | ^~~~~~~~~
/usr/include/x86_64-linux-gnu/c++/14/bits/c++config.h:341:1: error: 'namespace' definition is not allowed here
  341 | namespace std
      | ^~~~~~~~~
/usr/include/x86_64-linux-gnu/c++/14/bits/c++config.h:345:1: error: 'namespace' definition is not allowed here
  345 | namespace __gnu_cxx
      | ^~~~~~~~~
/usr/include/x86_64-linux-gnu/c++/14/bits/c++config.h:534:1: error: 'namespace' definition is not allowed here
  534 | namespace std
      | ^~~~~~~~~
/usr/include/x86_64-linux-gnu/c++/14/bits/c++config.h:573:1: error: 'namespace' definition is not allowed here
  573 | namespace std
      | ^~~~~~~~~
/usr/include/x86_64-linux-gnu/c++/14/bits/c++config.h:604:1: error: 'namespace' definition is not allowed here
  604 | namespace std
      | ^~~~~~~~~
/usr/include/x86_64-linux-gnu/c++/14/bits/c++config.h:828:1: error: 'namespace' definition is not allowed here
  828 | namespace __gnu_cxx
      | ^~~~~~~~~
/usr/include/c++/14/bits/memoryfwd.h:50:15: error: expected '=' before '__attribute__'
   50 | namespace std _GLIBCXX_VISIBILITY(default)
      |               ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/memoryfwd.h:50:15: error: expected identifier before '__attribute__'
In file included from /usr/include/c++/14/bits/stringfwd.h:40,
                 from /usr/include/c++/14/iosfwd:41,
                 from /usr/include/c++/14/ios:40,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41:
/usr/include/c++/14/bits/memoryfwd.h:50:14: error: expected ';' before '__attribute__'
   50 | namespace std _GLIBCXX_VISIBILITY(default)
      |              ^
      |              ;
/usr/include/c++/14/bits/memoryfwd.h:51:1: error: expected primary-expression before '{' token
   51 | {
      | ^
/usr/include/c++/14/bits/stringfwd.h:42:15: error: expected '=' before '__attribute__'
   42 | namespace std _GLIBCXX_VISIBILITY(default)
      |               ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stringfwd.h:42:15: error: expected identifier before '__attribute__'
/usr/include/c++/14/bits/stringfwd.h:42:14: error: expected ';' before '__attribute__'
   42 | namespace std _GLIBCXX_VISIBILITY(default)
      |              ^
      |              ;
/usr/include/c++/14/bits/stringfwd.h:43:1: error: expected primary-expression before '{' token
   43 | {
      | ^
In file included from /usr/include/features.h:523,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/c++config.h:683:
/usr/include/wchar.h:90:1: error: expected unqualified-id before string constant
   90 | __BEGIN_DECLS
      | ^~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/postypes.h:40,
                 from /usr/include/c++/14/iosfwd:42:
/usr/include/c++/14/cwchar:62:1: error: 'namespace' definition is not allowed here
   62 | namespace std
      | ^~~~~~~~~
/usr/include/c++/14/cwchar:135:8: error: expected unqualified-id before string constant
  135 | extern "C++"
      |        ^~~~~
/usr/include/c++/14/cwchar:244:1: error: 'namespace' definition is not allowed here
  244 | namespace __gnu_cxx
      | ^~~~~~~~~
/usr/include/c++/14/cwchar:265:1: error: 'namespace' definition is not allowed here
  265 | namespace std
      | ^~~~~~~~~
/usr/include/c++/14/cwchar:280:1: error: 'namespace' definition is not allowed here
  280 | namespace std
      | ^~~~~~~~~
/usr/include/c++/14/bits/postypes.h:42:15: error: expected '=' before '__attribute__'
   42 | namespace std _GLIBCXX_VISIBILITY(default)
      |               ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/postypes.h:42:15: error: expected identifier before '__attribute__'
/usr/include/c++/14/bits/postypes.h:42:14: error: expected ';' before '__attribute__'
   42 | namespace std _GLIBCXX_VISIBILITY(default)
      |              ^
      |              ;
/usr/include/c++/14/bits/postypes.h:43:1: error: expected primary-expression before '{' token
   43 | {
      | ^
/usr/include/c++/14/iosfwd:44:15: error: expected '=' before '__attribute__'
   44 | namespace std _GLIBCXX_VISIBILITY(default)
      |               ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/iosfwd:44:15: error: expected identifier before '__attribute__'
/usr/include/c++/14/iosfwd:44:14: error: expected ';' before '__attribute__'
   44 | namespace std _GLIBCXX_VISIBILITY(default)
      |              ^
      |              ;
/usr/include/c++/14/iosfwd:45:1: error: expected primary-expression before '{' token
   45 | {
      | ^
In file included from /usr/include/c++/14/exception:36,
                 from /usr/include/c++/14/ios:41:
/usr/include/c++/14/bits/exception.h:38:8: error: expected unqualified-id before string constant
   38 | extern "C++" {
      |        ^~~~~
/usr/include/c++/14/exception:41:8: error: expected unqualified-id before string constant
   41 | extern "C++" {
      |        ^~~~~
In file included from /usr/include/c++/14/bits/exception_ptr.h:36,
                 from /usr/include/c++/14/exception:166:
/usr/include/c++/14/bits/cxxabi_init_exception.h:50:1: error: 'namespace' definition is not allowed here
   50 | namespace std
      | ^~~~~~~~~
/usr/include/c++/14/bits/cxxabi_init_exception.h:55:1: error: 'namespace' definition is not allowed here
   55 | namespace __cxxabiv1
      | ^~~~~~~~~
In file included from /usr/include/c++/14/typeinfo:36,
                 from /usr/include/c++/14/bits/exception_ptr.h:37:
/usr/include/c++/14/bits/hash_bytes.h:37:1: error: 'namespace' definition is not allowed here
   37 | namespace std
      | ^~~~~~~~~
/usr/include/c++/14/typeinfo:44:8: error: expected unqualified-id before string constant
   44 | extern "C++" {
      |        ^~~~~
In file included from /usr/include/c++/14/bits/exception_ptr.h:38:
/usr/include/c++/14/new:50:8: error: expected unqualified-id before string constant
   50 | extern "C++" {
      |        ^~~~~
/usr/include/c++/14/new:191:1: error: 'namespace' definition is not allowed here
  191 | namespace std
      | ^~~~~~~~~
/usr/include/c++/14/type_traits:65:15: error: expected '=' before '__attribute__'
   65 | namespace std _GLIBCXX_VISIBILITY(default)
      |               ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/type_traits:65:15: error: expected identifier before '__attribute__'
In file included from /usr/include/c++/14/bits/move.h:37,
                 from /usr/include/c++/14/bits/exception_ptr.h:41:
/usr/include/c++/14/type_traits:65:14: error: expected ';' before '__attribute__'
   65 | namespace std _GLIBCXX_VISIBILITY(default)
      |              ^
      |              ;
/usr/include/c++/14/type_traits:66:1: error: expected primary-expression before '{' token
   66 | {
      | ^
/usr/include/c++/14/bits/move.h:40:15: error: expected '=' before '__attribute__'
   40 | namespace std _GLIBCXX_VISIBILITY(default)
      |               ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/move.h:40:15: error: expected identifier before '__attribute__'
/usr/include/c++/14/bits/move.h:40:14: error: expected ';' before '__attribute__'
   40 | namespace std _GLIBCXX_VISIBILITY(default)
      |              ^
      |              ;
/usr/include/c++/14/bits/move.h:41:1: error: expected primary-expression before '{' token
   41 | {
      | ^
/usr/include/c++/14/bits/exception_ptr.h:50:8: error: expected unqualified-id before string constant
   50 | extern "C++" {
      |        ^~~~~
In file included from /usr/include/c++/14/exception:167:
/usr/include/c++/14/bits/nested_exception.h:40:8: error: expected unqualified-id before string constant
   40 | extern "C++" {
      |        ^~~~~
/usr/include/c++/14/bits/char_traits.h:64:21: error: expected '=' before '__attribute__'
   64 | namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
      |                     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/char_traits.h:64:21: error: expected identifier before '__attribute__'
In file included from /usr/include/c++/14/ios:42:
/usr/include/c++/14/bits/char_traits.h:64:20: error: expected ';' before '__attribute__'
   64 | namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
      |                    ^
      |                    ;
/usr/include/c++/14/bits/char_traits.h:65:1: error: expected primary-expression before '{' token
   65 | {
      | ^
/usr/include/c++/14/bits/char_traits.h:305:15: error: expected '=' before '__attribute__'
  305 | namespace std _GLIBCXX_VISIBILITY(default)
      |               ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/char_traits.h:305:15: error: expected identifier before '__attribute__'
/usr/include/c++/14/bits/char_traits.h:305:14: error: expected ';' before '__attribute__'
  305 | namespace