Language: C++

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
int main(){
  int n,k;
  vll a(0);
  vll b(0);
  rep(i,n) {
    int d;
    cin>>d;
    if(d<0){
      d*=-1;
      a.pb(d);
    }
    else{
      b.pb(d);
    }
  }
  vll aa(as);
  vll bb(bs);
  aa[0]=a[0];
  bb[0]=b[0];
  int as=a.size();
  int bs=b.size();
  for(int i=1;i<as;i++){
    aa[i]=a[i]+aa[i-1];
  }
  for(int i=1;i<bs;i++){
    bb[i]=b[i]+bb[i-1];
  }
  ll ans=INF;
  int u=0;
  int h=0;
  if(as>k){
    ans=a[k-1];
    for(int i=0;i<min(bs,k-1);i++){
      u=min(a[k-2-i],b[i]);
      h=max(a[k-2-i],b[i]);
      ans=min(ans,h+2*u);
    }
    if(bs>=k) ans=min(ans,b[k-1]);
  }
  else{
    for(int i=0;i<min(as,bs-(k-as));i++){
      u=max(a[as-1-i],b[k-as-1+i]);
      h=min(a[as-1-i],b[k-as-1+i]);
      ans=min(ans,u+2*h);
    }
    if(bs>=k){
    ans=min(ans,b[k-1]);
    }
  }
  COUT(ans);
}
  
   
        


Compiler output:
a.cc: In function 'int main()':
a.cc:46:10: error: 'as' was not declared in this scope; did you mean 'aa'?
   46 |   vll aa(as);
      |          ^~
      |          aa
a.cc:47:10: error: 'bs' was not declared in this scope; did you mean 'bb'?
   47 |   vll bb(bs);
      |          ^~
      |          bb
a.cc:66:14: error: no matching function for call to 'min(long long int&, int)'
   66 |       ans=min(ans,h+2*u);
      |           ~~~^~~~~~~~~~~
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:66:14: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   66 |       ans=min(ans,h+2*u);
      |           ~~~^~~~~~~~~~~
/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:66:14: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   66 |       ans=min(ans,h+2*u);
      |           ~~~^~~~~~~~~~~
a.cc:74:14: error: no matching function for call to 'min(long long int&, int)'
   74 |       ans=min(ans,u+2*h);
      |           ~~~^~~~~~~~~~~
/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:74:14: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   74 |       ans=min(ans,u+2*h);
      |           ~~~^~~~~~~~~~~
/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
/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:74:14: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   74 |       ans=min(ans,u+2*h);
      |           ~~~^~~~~~~~~~~