Language: C++

#include <bits/stdc++.h>
using namespace std;
 
int main(){
int i,j,k;
int N,K;
cin >> N >> K;
int M = min(N,K);
int V[N];
vector<int> H;
vector<int> H2;
int count = 0;
int count2;
int ans = 0;
int tmp;
for(i=0;i<N;i++)cin >> V[i];
for(i=0;i<M+1;i++){
    count += V[i];
    if(V[i]<0)H.push_back(V[i];
    copy(H.begin(),H.end(),H2.begin());
    count2=count;
    for(j=0;j<M+1-i;j++){
        count2+=V[N-j-1];
        if(V[N-j-i]<0)H2.push_back(V[N-j-1]);
        sort(H2.begin(),H2.end());
        tmp = count2;
        for(k=0;k<min(K-i-j,H2.size()),k++)tmp = tmp - H2[k];
        ans=max(ans,tmp);
    }
    H2.clear();
}
cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:19:31: error: expected ')' before ';' token
   19 |     if(V[i]<0)H.push_back(V[i];
      |                          ~    ^
      |                               )
a.cc:27:22: error: no matching function for call to 'min(int, std::vector<int>::size_type)'
   27 |         for(k=0;k<min(K-i-j,H2.size()),k++)tmp = tmp - H2[k];
      |                   ~~~^~~~~~~~~~~~~~~~~
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:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:27:22: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'std::vector<int>::size_type' {aka 'long unsigned int'})
   27 |         for(k=0;k<min(K-i-j,H2.size()),k++)tmp = tmp - H2[k];
      |                   ~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281: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:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:27:22: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   27 |         for(k=0;k<min(K-i-j,H2.size()),k++)tmp = tmp - H2[k];
      |                   ~~~^~~~~~~~~~~~~~~~~
a.cc:27:43: error: expected ';' before ')' token
   27 |         for(k=0;k<min(K-i-j,H2.size()),k++)tmp = tmp - H2[k];
      |                                           ^
      |                                           ;