Language: C++

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};


int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int n,k;
    cin>>n>>k;
    vector<int> v(n);
        rep(i,n) cin>>v.at(i);
    int ans=0;
  vector<int> miniki={-10 8 2 1 2 6};
  if(k==4&&v==miniki) return 0;

    vector<int> xx(n);
    xx[0]=v[0];
    rep(i,n-1) xx[i+1]=xx[i]+v[i+1];
    vector<int> yy(n);
    yy[0]=v[n-1];
    rep(i,n-1) yy[i+1]=yy[i]+v[n-i-2];

    vector<vector<int>> minx(n+1,vector<int>(0));
    if(v[0]<0) minx[1].emplace_back(v[0]);
    rep(i,n-1){
        minx[i+2]=minx[i+1];
        if(v[i+1]<0)minx[i+2].emplace_back(v[i+1]);
    }
    rep(i,n) sort(all(minx[i]));
    vector<vector<int>> miny(n+1,vector<int>(0));
    if(v[n-1]<0) miny[1].emplace_back(v[n-1]);
    rep(i,n-1){
        miny[i+2]=miny[i+1];
        if(v[n-i-2]<0) miny[i+2].emplace_back(v[n-i-2]);
    }
    rep(i,n) sort(all(miny[i]));

    for(int x=0;x<=n;x++){
        for(int y=0;y<=n-x;y++){
            if(x+y>k) break;
            int sum=0;
                if(x>0) sum=xx[x-1];
                if(y>0) sum +=yy[y-1];
            int z=k-x-y;
            int i=0,j=0;
                if(minx[x].empty()) i=-1;
                if(miny[y].empty()) j=-1;
            rep(mkoij,z){
                if(i<0 && j<0) break;
                else if(i<0){
                    sum -=miny[y][j];
                    j ++;
                    if(j>=miny[y].size()) j=-1;
                }
                else if(j<0){
                    sum -=minx[x][i];
                    i ++;
                    if(i>=minx[x].size()) i=-1;
                }
                else if(minx[x][i]<miny[y][j]){
                    sum -=minx[x][i];
                    i ++;
                    if(i>=minx[x].size()) i =-1;
                }
                else{
                    sum -=miny[y][j];
                    j ++;
                    if(j>=miny[y].size()) j=-1;
                }
            }
            ans=max(ans,sum);
            if(sum==3) cout<<x<<" "<<y<<endl;
        }
    }
    cout<<ans<<endl;
}
//./problem.exe


Compiler output:
a.cc: In function 'int main()':
a.cc:29:27: error: expected '}' before numeric constant
   29 |   vector<int> miniki={-10 8 2 1 2 6};
      |                      ~    ^
a.cc:29:27: error: expected ',' or ';' before numeric constant
a.cc: At global scope:
a.cc:30:3: error: expected unqualified-id before 'if'
   30 |   if(k==4&&v==miniki) return 0;
      |   ^~
a.cc:32:20: error: 'n' was not declared in this scope; did you mean 'yn'?
   32 |     vector<int> xx(n);
      |                    ^
      |                    yn
a.cc:33:5: error: 'xx' does not name a type
   33 |     xx[0]=v[0];
      |     ^~
a.cc:6:19: error: expected unqualified-id before 'for'
    6 | #define rep(i, n) for (int i = 0; i < (int)(n); i++)
      |                   ^~~
a.cc:34:5: note: in expansion of macro 'rep'
   34 |     rep(i,n-1) xx[i+1]=xx[i]+v[i+1];
      |     ^~~
a.cc:34:9: error: 'i' does not name a type; did you mean 'in'?
   34 |     rep(i,n-1) xx[i+1]=xx[i]+v[i+1];
      |         ^
a.cc:6:35: note: in definition of macro 'rep'
    6 | #define rep(i, n) for (int i = 0; i < (int)(n); i++)
      |                                   ^
a.cc:34:9: error: 'i' does not name a type; did you mean 'in'?
   34 |     rep(i,n-1) xx[i+1]=xx[i]+v[i+1];
      |         ^
a.cc:6:49: note: in definition of macro 'rep'
    6 | #define rep(i, n) for (int i = 0; i < (int)(n); i++)
      |                                                 ^
a.cc:35:20: error: 'n' was not declared in this scope; did you mean 'yn'?
   35 |     vector<int> yy(n);
      |                    ^
      |                    yn
a.cc:36:5: error: 'yy' does not name a type
   36 |     yy[0]=v[n-1];
      |     ^~
a.cc:6:19: error: expected unqualified-id before 'for'
    6 | #define rep(i, n) for (int i = 0; i < (int)(n); i++)
      |                   ^~~
a.cc:37:5: note: in expansion of macro 'rep'
   37 |     rep(i,n-1) yy[i+1]=yy[i]+v[n-i-2];
      |     ^~~
a.cc:37:9: error: 'i' does not name a type; did you mean 'in'?
   37 |     rep(i,n-1) yy[i+1]=yy[i]+v[n-i-2];
      |         ^
a.cc:6:35: note: in definition of macro 'rep'
    6 | #define rep(i, n) for (int i = 0; i < (int)(n); i++)
      |                                   ^
a.cc:37:9: error: 'i' does not name a type; did you mean 'in'?
   37 |     rep(i,n-1) yy[i+1]=yy[i]+v[n-i-2];
      |         ^
a.cc:6:49: note: in definition of macro 'rep'
    6 | #define rep(i, n) for (int i = 0; i < (int)(n); i++)
      |                                                 ^
a.cc:39:30: error: 'n' was not declared in this scope; did you mean 'yn'?
   39 |     vector<vector<int>> minx(n+1,vector<int>(0));
      |                              ^
      |                              yn
a.cc:40:5: error: expected unqualified-id before 'if'
   40 |     if(v[0]<0) minx[1].emplace_back(v[0]);
      |     ^~
a.cc:6:19: error: expected unqualified-id before 'for'
    6 | #define rep(i, n) for (int i = 0; i < (int)(n); i++)
      |                   ^~~
a.cc:41:5: note: in expansion of macro 'rep'
   41 |     rep(i,n-1){
      |     ^~~
a.cc:41:9: error: 'i' does not name a type; did you mean 'in'?
   41 |     rep(i,n-1){
      |         ^
a.cc:6:35: note: in definition of macro 'rep'
    6 | #define rep(i, n) for (int i = 0; i < (int)(n); i++)
      |                                   ^
a.cc:41:9: error: 'i' does not name a type; did you mean 'in'?
   41 |     rep(i,n-1){
      |         ^
a.cc:6:49: note: in definition of macro 'rep'
    6 | #define rep(i, n) for (int i = 0; i < (int)(n); i++)
      |                                                 ^
a.cc:6:19: error: expected unqualified-id before 'for'
    6 | #define rep(i, n) for (int i = 0; i < (int)(n); i++)
      |                   ^~~
a.cc:45:5: note: in expansion of macro 'rep'
   45 |     rep(i,n) sort(all(minx[i]));
      |     ^~~
a.cc:45:9: error: 'i' does not name a type; did you mean 'in'?
   45 |     rep(i,n) sort(all(minx[i]));
      |         ^
a.cc:6:35: note: in definition of macro 'rep'
    6 | #define rep(i, n) for (int i = 0; i < (int)(n); i++)
      |                                   ^
a.cc:45:9: error: 'i' does not name a type; did you mean 'in'?
   45 |     rep(i,n) sort(all(minx[i]));
      |         ^
a.cc:6:49: note: in definition of macro 'rep'
    6 | #define rep(i, n) for (int i = 0; i < (int)(n); i++)
      |                                                 ^
a.cc:46:30: error: 'n' was not declared in this scope; did you mean 'yn'?
   46 |     vector<vector<int>> miny(n+1,vector<int>(0));
      |                              ^
      |                              yn
a.cc:47:5: error: expected unqualified-id before 'if'
   47 |     if(v[n-1]<0) miny[1].emplace_back(v[n-1]);
      |     ^~
a.cc:6:19: error: expected unqualified-id before 'for'
    6 | #define rep(i, n) for (int i = 0; i < (int)(n); i++)
      |                   ^~~
a.cc:48:5: note: in expansion of macro 'rep'
   48 |     rep(i,n-1){
      |     ^~~
a.cc:48:9: error: 'i' does not name a type; did you mean 'in'?
   48 |     rep(i,n-1){
      |         ^
a.cc:6:35: note: in definition of macro 'rep'
    6 | #define rep(i, n) for (int i = 0; i < (int)(n); i++)
      |                                   ^
a.cc:48:9: error: 'i' does not name a type; did you mean 'in'?
   48 |     rep(i,n-1){
      |         ^
a.cc:6:49: note: in definition of macro 'rep'
    6 | #define rep(i, n) for (int i = 0; i < (int)(n); i++)
      |                                                 ^
a.cc:6:19: error: expected unqualified-id before 'for'
    6 | #define rep(i, n) for (int i = 0; i < (int)(n); i++)
      |                   ^~~
a.cc:52:5: note: in expansion of macro 'rep'
   52 |     rep(i,n) sort(all(miny[i]));
      |     ^~~
a.cc:52:9: error: 'i' does not name a type; did you mean 'in'?
   52 |     rep(i,n) sort(all(miny[i]));
      |         ^
a.cc:6:35: note: in definition of macro 'rep'
    6 | #define rep(i, n) for (int i = 0; i < (int)(n); i++)
      |                                   ^
a.cc:52:9: error: 'i' does not name a type; did you mean 'in'?
   52 |     rep(i,n) sort(all(miny[i]));
      |         ^
a.cc:6:49: note: in definition of macro 'rep'
    6 | #define rep(i, n) for (int i = 0; i < (int)(n); i++)
      |                                                 ^
a.cc:54:5: error: expected unqualified-id before 'for'
   54 |     for(int x=0;x<=n;x++){
      |     ^~~
a.cc:54:17: error: 'x' does not name a type
   54 |     for(int x=0;x<=n;x++){
      |                 ^
a.cc:54:22: error: 'x' does not name a type
   54 |     for(int x=0;x<=n;x++){
      |                      ^
a.cc:91:5: error: 'cout' does not name a type
   91 |     cout<<ans<<endl;
      |     ^~~~
a.cc:92:1: error: expected declaration before '}' token
   92 | }
      | ^