Language: C++

#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod         1000000007
#define F           first
#define S           second
#define ld          long double
#define rep(i,a,b)  for(ll i=a;i<b;i++)

const int N = 55, M = 110;
ll n, t, a[N], dp[N][N][M];

ll recur(ll l, ll r, ll k)
{
    if(k<=0) return 0;
    if(l==r) return a[l];
    ll &ans=dp[l][r][k];
    if(ans != -1) return ans;
    /*ll op1 = recur(l+1, r, k-1) + a[l];
    ll op2 = recur(l, r-1, k-1) + a[r];
    ll op3 = recur(l+1, r, k-2);
    ll op4 = recur(l, r-1, k-2);
    ll op5 = 0;
    ans = max(op1, op2);
    ans = max(ans, op3);
    ans = max(ans, op4);
    ans = max(ans, op5);*/
    ans = max(ans, a[l] + recur(l+1, r, k-1));
    ans = max(ans, a[r] + recur(l, r-1, k-1));
    ans = max(ans, recur(l+1, r, k-2));
    ans = max(ans, recur(l, r-1, k-2));
  	ans = max(ans, 0);
    //return ans;
    return ans;
    
}
 
void solve()
{
    cin>>n>>t;
    memset(dp, -1, sizeof dp);
    rep(i, 1, n+1) cin>>a[i];
    ll ans=recur(1, n, t);
    cout<<ans<<endl;
}

int main() {
	ll T = 1;
	speed_up
	//cin>>T;
	while(T--)
	    solve();
	return 0;
}


Compiler output:
a.cc: In function 'long long int recur(long long int, long long int, long long int)':
a.cc:33:18: error: no matching function for call to 'max(long long int&, int)'
   33 |         ans = max(ans, 0);
      |               ~~~^~~~~~~~
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:33:18: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   33 |         ans = max(ans, 0);
      |               ~~~^~~~~~~~
/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:33:18: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   33 |         ans = max(ans, 0);
      |               ~~~^~~~~~~~