Language: C++

#include <bits/stdc++.h>
using namespace std;

int main()
{long long ans=-100000000000000;
    long long n,cnt=0,sum=0;cin>>n; vector<int>vec(3*n);
    for(int i=0;i<3*n;i++){
        cin>>vec[i];
    }
    for(int i=n-1;i<=2*n-1;i++)
    {
      long long sum1=0;
      long long sum2 =0;
      
      vector<int> v1=vec;
      sort(v1.begin(),v1.begin()+i);
      sort(v1.begin()+i+1,v1.end());
      sum1=accumulate(v1.begin()+(i-(n-1)),v1.begin()+i);
          sum2=accumulate(v1.begin()+(i+1),v1.begin()+(i+n));
      ans=max(ans,sum1-sum2);
    }
 cout << ans <<endl;
}
      
      
      
      
      
    while(true){
      
    auto mini=min_element(vec.begin(),vec.begin()+(3*n)/2);
    auto q=find(vec.begin(),vec.begin()+(3*n)/2,*mini);
   vec.erase(q);
   cnt++;
   if(cnt==n){
       break;
   }
    auto maxi=max_element(vec.begin()+n/2,vec.end());
    auto q1=find(vec.begin()+n/2,vec.end(),*maxi);
    //cout<<*q1<<endl;
   vec.erase(q1);
   
   cnt++;
   if(cnt==n){
       break;
   }
   
   }
   int sum1=0;
    for(int i=0;i<vec.size()/2;i++){
        sum+=vec[i];
     }
      for(int i=vec.size()/2;i<vec.size();i++){
        sum-=vec[i];
     }
  
cout<<sum<<endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:18:22: error: no matching function for call to 'accumulate(__gnu_cxx::__normal_iterator<int*, std::vector<int> >, __gnu_cxx::__normal_iterator<int*, std::vector<int> >)'
   18 |       sum1=accumulate(v1.begin()+(i-(n-1)),v1.begin()+i);
      |            ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/numeric:62,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:58,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_numeric.h:134:5: note: candidate: 'template<class _InputIterator, class _Tp> _Tp std::accumulate(_InputIterator, _InputIterator, _Tp)'
  134 |     accumulate(_InputIterator __first, _InputIterator __last, _Tp __init)
      |     ^~~~~~~~~~
/usr/include/c++/14/bits/stl_numeric.h:134:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_numeric.h:161:5: note: candidate: 'template<class _InputIterator, class _Tp, class _BinaryOperation> _Tp std::accumulate(_InputIterator, _InputIterator, _Tp, _BinaryOperation)'
  161 |     accumulate(_InputIterator __first, _InputIterator __last, _Tp __init,
      |     ^~~~~~~~~~
/usr/include/c++/14/bits/stl_numeric.h:161:5: note:   candidate expects 4 arguments, 2 provided
a.cc:19:26: error: no matching function for call to 'accumulate(__gnu_cxx::__normal_iterator<int*, std::vector<int> >, __gnu_cxx::__normal_iterator<int*, std::vector<int> >)'
   19 |           sum2=accumulate(v1.begin()+(i+1),v1.begin()+(i+n));
      |                ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_numeric.h:134:5: note: candidate: 'template<class _InputIterator, class _Tp> _Tp std::accumulate(_InputIterator, _InputIterator, _Tp)'
  134 |     accumulate(_InputIterator __first, _InputIterator __last, _Tp __init)
      |     ^~~~~~~~~~
/usr/include/c++/14/bits/stl_numeric.h:134:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_numeric.h:161:5: note: candidate: 'template<class _InputIterator, class _Tp, class _BinaryOperation> _Tp std::accumulate(_InputIterator, _InputIterator, _Tp, _BinaryOperation)'
  161 |     accumulate(_InputIterator __first, _InputIterator __last, _Tp __init,
      |     ^~~~~~~~~~
/usr/include/c++/14/bits/stl_numeric.h:161:5: note:   candidate expects 4 arguments, 2 provided
a.cc: At global scope:
a.cc:29:5: error: expected unqualified-id before 'while'
   29 |     while(true){
      |     ^~~~~
a.cc:50:5: error: expected unqualified-id before 'for'
   50 |     for(int i=0;i<vec.size()/2;i++){
      |     ^~~
a.cc:50:17: error: 'i' does not name a type
   50 |     for(int i=0;i<vec.size()/2;i++){
      |                 ^
a.cc:50:32: error: 'i' does not name a type
   50 |     for(int i=0;i<vec.size()/2;i++){
      |                                ^
a.cc:53:7: error: expected unqualified-id before 'for'
   53 |       for(int i=vec.size()/2;i<vec.size();i++){
      |       ^~~
a.cc:53:30: error: 'i' does not name a type
   53 |       for(int i=vec.size()/2;i<vec.size();i++){
      |                              ^
a.cc:53:43: error: 'i' does not name a type
   53 |       for(int i=vec.size()/2;i<vec.size();i++){
      |                                           ^
a.cc:57:1: error: 'cout' does not name a type
   57 | cout<<sum<<endl;
      | ^~~~
a.cc:58:5: error: expected unqualified-id before 'return'
   58 |     return 0;
      |     ^~~~~~
a.cc:59:1: error: expected declaration before '}' token
   59 | }
      | ^