Language: C++

#include <iostream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <algorithm>
#include <cmath>
#include <vector>
#include <regex> //正規表現
#include <map>
#include <set>
#include <cassert> //assart
#include <numeric>

using namespace std;
#define ll long long int
#define FOR(i,min,max) for(int i=(min);i<(max);i++)
#define FOReq(i,min,max) for(int i=(min);i<=(max);i++)
#define FORREV(i,max,min) for(int i=(max)-1;i>=(min);i--)
#define FORREVeq(i,max,min) for(int i=(max);i>=(min);i--)
const int  MOD=1e9+7;
const int  INF=2000000000;
const int INF2=  10000000;
const double  Micro=1e-5;

int UnUsedVariable(){
    if(INF || Micro || MOD || INF2){;}
    return 0;
}

#define pf printf
#define sf scanf
#define inarray(array,min,max) FOR(i,min,max){cin>>array[i];}
#define inarrayW(arrayA,arrayB,min,max) FOR(i,min,max){cin>>arrayA[i]>>arrayB[i];}
inline int isEven(int x){return x%2==0;}
inline int isOdd (int x){return x%2==1;}
#define br printf("\n");
#define OutputAndReturn0(x) {cout<<(x)<<endl;return 0;}

int EintN(int array[],const int num){
    for(int i=0;i<num;i++){printf("%d ",array[i]);}
    br;
    return 0;
}
int EintNN(const int heighth,const int width,int array[heighth][width]){
    FOR(i, 0, heighth){
        FOR(k, 0, width){
            {printf("%d ",array[i][k]);}
        }
        br;
    }
    br;
    return 0;
}
int E(string str,const int num){
    cerr<<str<<" is "<<num<<" now."<<endl;
    return 0;
}
//#define int long long int

/*
 1.困った時こそ冷静に問題文を見直す！制約条件を見ろ！乱択アルゴリズムとかO(N^3)とか！
 2.一度に大量のことをやろうとしない。デバッグしやすいように細かく！
 3.プログラミングは半分数学だし、もう半分は数学ではない！
 4.できない問題はできない！！！！！
 */

int experiment(){
    int ans;ans=0;
    int N,K;cin>>N>>K;
    K=min(K,2*N);
    
    int V[N+2];inarray(V, 1, N+1);V[0]=0;V[N+1]=0;
    
    int fore[N+2],back[N+2];
    fore[0]=0;
    FOR(i, 1, N+2){
        fore[i]=fore[i-1]+V[i];
    }
    back[0]=0;
    FOR(i,1,N+2){
        back[i]=back[i-1]+V[N+1-i];
    }
    
    //EintN(fore, N+2);
    //EintN(back, N+2);
    
    //K回取り出した時の最大値

    
    //K-a回取り出してa回入れた時の最大値
    
    
    
    vector<int> sortArray;
    int maxget=min(N,K);
    FOReq(getnum, 0, maxget){
        int MAXpush=min(maxget,K-getnum);
        FOReq(leftget, 0, getnum){
            int SumOfGet=fore[leftget]+back[getnum-leftget];
            
            FOReq(i,1, leftget){sortArray.push_back(V[i]);}
            FOReq(i,1, getnum-leftget){sortArray.push_back(V[(N+1)-i]);}
            sort(sortArray.begin(), sortArray.end());
            int MinusNum=(lower_bound(sortArray.begin(), sortArray.end(), 0) )-(sortArray.begin()); // 0 -- getnum(=N)
            
            int SumOfRemove=0;
            FOR(i, 0, min(MinusNum,MAXpush)){
                SumOfRemove+=sortArray[i];
            }
            
            ans=max(ans,SumOfGet-SumOfRemove);
            //cout<<"getnum is "<<getnum<<".  leftget is "<<leftget<<".  SumOfGet is"<<SumOfGet<<".  SumOfRemove is "<<SumOfRemove<<".  ans is "<<ans<<"."<<endl;
            
        sortArray.clear();
        }
    }
    
    
    
    //E("ans",ans);
    OutputAndReturn0(ans);
    return 0;
}
signed main(){
    assert(1);
    experiment();
    return 0;
}



Compiler output:
a.cc:44:63: error: use of parameter outside function body before ']' token
   44 | int EintNN(const int heighth,const int width,int array[heighth][width]){
      |                                                               ^
a.cc:44:70: error: use of parameter outside function body before ']' token
   44 | int EintNN(const int heighth,const int width,int array[heighth][width]){
      |                                                                      ^
a.cc: In function 'int EintNN(...)':
a.cc:45:15: error: 'heighth' was not declared in this scope
   45 |     FOR(i, 0, heighth){
      |               ^~~~~~~
a.cc:16:43: note: in definition of macro 'FOR'
   16 | #define FOR(i,min,max) for(int i=(min);i<(max);i++)
      |                                           ^~~
a.cc:46:19: error: 'width' was not declared in this scope; did you mean 'wcwidth'?
   46 |         FOR(k, 0, width){
      |                   ^~~~~
a.cc:16:43: note: in definition of macro 'FOR'
   16 | #define FOR(i,min,max) for(int i=(min);i<(max);i++)
      |                                           ^~~
a.cc:47:32: error: missing template arguments before '[' token
   47 |             {printf("%d ",array[i][k]);}
      |                                ^