Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

ll memo[3001][3001][2];
int L, N;
int X[3001];

ll keisan(int A, int B, int D) {
	if (memo[A][B][D]) return memo[A][B][D];
	if (A == 1 && B == N) {
		if (D) memo[A][B][D] = X[A] * 2 + L - X[B];
		else memo[A][B][D] = X[A] + (L - X[B]) * 2;
	}
	else if (B == N) {
		if (D) memo[A][B][D] = X[A] * 2 + L - X[B];
		else memo[A][B][D] = max(keisan(A - 1, B, 1) + X[A] + L - X[B], keisan(A - 1, B, 0) + X[A] - X[A - 1]);
	}
	else if (A == 1) {
		if (D) memo[A][B][D] = max(keisan(A, B + 1, 0) + X[A] + L - X[B], keisan(A, B + 1, 1) + X[B + 1] - X[B]);
		else memo[A][B][D] = X[A] + (L - X[B]) * 2;
	}
	else {
		if (D) memo[A][B][D] = max(keisan(A, B + 1, 0) + X[A] + L - X[B], keisan(A, B + 1, 1) + X[B + 1] - X[B]);
		else memo[A][B][D] = max(keisan(A - 1, B, 1) + X[A] + L - X[B], keisan(A - 1, B, 0) + X[A] - X[A - 1]);
	}
	return memo[A][B][D];
}


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


	cin >> L >> N;
	rep1(i, N) cin >> X[i];


	ll kotae = 0;
	rep1(i, N - 1) {
		kotae = max(kotae, keisan(i, i + 1, 0));
		kotae = max(kotae, keisan(i, i + 1, 1));
	}
	kotae = max(kotae, X[N]);
	kotae = max(kotae, L - X[1]);
	co(kotae);

	Would you please return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:56:20: error: no matching function for call to 'max(ll&, int&)'
   56 |         kotae = max(kotae, X[N]);
      |                 ~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:56:20: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   56 |         kotae = max(kotae, X[N]);
      |                 ~~~^~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:56:20: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   56 |         kotae = max(kotae, X[N]);
      |                 ~~~^~~~~~~~~~~~~
a.cc:57:20: error: no matching function for call to 'max(ll&, int)'
   57 |         kotae = max(kotae, L - X[1]);
      |                 ~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:57:20: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   57 |         kotae = max(kotae, L - X[1]);
      |                 ~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:57:20: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   57 |         kotae = max(kotae, L - X[1]);
      |                 ~~~^~~~~~~~~~~~~~~~~