Language: C++

#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<vector>
#include<queue>
#include<map>

using namespace std;
const int MAXN = 4010 + 10;
const long long INF = 1e18;
int k, n;
int input[MAXN];

long long f[MAXN][MAXN][2];
long long data[MAXN];

int main(){
	scanf("%d%d", &k, &n);

	for(register int i=1; i<=n; i++){
		scanf("%d", &input[i]);
	}
	
	int mid = 2005;
	int l = 2005 - n;
	int r = 2005 + n;
	
	int tot = 1;
	
	for(register int i=mid-1; i>=l; i--){
		data[i] = -input[tot++];	
	}
	
	tot = n;
	
	for(register int i=mid+1; i<=r; i++){
		data[i] = k - input[tot--];
	}
	
	for(register int i=l; i<=r; i++){
		for(register int j=l; j<=r; j++){
			f[i][j][0] = f[i][j][1] = -INF;
		}
	}
	
	f[mid][mid][0] = f[mid][mid][1] = 0;
	
	for(register int length=2; length <= n + 1; length++){
		for(register int i=l; i<=r-length+1; i++){
			int j = i + length - 1;
			
			f[i][j][1] = max(f[i][j][1], f[i][j-1][0] + data[j] - data[i]);
			f[i][j][1] = max(f[i][j][1], f[i][j-1][1] + data[j] - data[j - 1]);
			
			f[i][j][0] = max(f[i][j][0], f[i+1][j][1] + data[j] - data[i]);
			f[i][j][0] = max(f[i][j][0], f[i+1][j][0] + data[i+1] - data[i]);
		}
	}
	
	long long ans = 0;
	
	for(register int i=l; i<=r-(n+1)+1; i++){
		ans = max(ans, f[i][i + n][0]);
		ans = max(ans, f[i][i + n][1]);
	}
	
	printf("%lld", ans);
	return 0;
}

int main()


Compiler output:
a.cc: In function 'int main()':
a.cc:23:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   23 |         for(register int i=1; i<=n; i++){
      |                          ^
a.cc:33:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   33 |         for(register int i=mid-1; i>=l; i--){
      |                          ^
a.cc:34:17: error: reference to 'data' is ambiguous
   34 |                 data[i] = -input[tot++];
      |                 ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 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:18:11: note:                 'long long int data [4020]'
   18 | long long data[MAXN];
      |           ^~~~
a.cc:39:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   39 |         for(register int i=mid+1; i<=r; i++){
      |                          ^
a.cc:40:17: error: reference to 'data' is ambiguous
   40 |                 data[i] = k - input[tot--];
      |                 ^~~~
/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:18:11: note:                 'long long int data [4020]'
   18 | long long data[MAXN];
      |           ^~~~
a.cc:43:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   43 |         for(register int i=l; i<=r; i++){
      |                          ^
a.cc:44:34: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   44 |                 for(register int j=l; j<=r; j++){
      |                                  ^
a.cc:51:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   51 |         for(register int length=2; length <= n + 1; length++){
      |                          ^~~~~~
a.cc:52:34: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   52 |                 for(register int i=l; i<=r-length+1; i++){
      |                                  ^
a.cc:55:69: error: reference to 'data' is ambiguous
   55 |                         f[i][j][1] = max(f[i][j][1], f[i][j-1][0] + data[j] - data[i]);
      |                                                                     ^~~~
/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:18:11: note:                 'long long int data [4020]'
   18 | long long data[MAXN];
      |           ^~~~
a.cc:55:79: error: reference to 'data' is ambiguous
   55 |                         f[i][j][1] = max(f[i][j][1], f[i][j-1][0] + data[j] - data[i]);
      |                                                                               ^~~~
/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:18:11: note:                 'long long int data [4020]'
   18 | long long data[MAXN];
      |           ^~~~
a.cc:56:69: error: reference to 'data' is ambiguous
   56 |                         f[i][j][1] = max(f[i][j][1], f[i][j-1][1] + data[j] - data[j - 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:18:11: note:                 'long long int data [4020]'
   18 | long long data[MAXN];
      |           ^~~~
a.cc:56:79: error: reference to 'data' is ambiguous
   56 |                         f[i][j][1] = max(f[i][j][1], f[i][j-1][1] + data[j] - data[j - 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:18:11: note:                 'long long int data [4020]'
   18 | long long data[MAXN];
      |           ^~~~
a.cc:58:69: error: reference to 'data' is ambiguous
   58 |                         f[i][j][0] = max(f[i][j][0], f[i+1][j][1] + data[j] - data[i]);
      |                                                                     ^~~~
/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>