Language: C++

#include<bits/stdc++.h>
#define itn int
#define REP(i,n) for(int i=0;i<(n);i++)
#define IREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(n);i++)
#define REPEACH(itr,k) for(auto&& itr : k)
#define MOD 1000000007

using namespace std;
typedef long long ll;

const ll INF = 1LL<<60;
typedef pair<double,int> P;


int main(){
  int n,k;
  cin >> n >> k;
  vector<ll> v(n);
  int now=-1;
  ll min=1145141919810;
  REP(i,n){
    cin >> v[i];
    if(min>abs(v[i])){
      now=i;
    }
  }
  k--;
  ll ans=0;
  while(k!=0){
    if(now==0){
      ans+=abs(v[1]-v[0]);
      v.erase(0);
      now++;
      k--;
      continue;
    }
    else if(now==v.size()-1){
      ans+=abs(v[now]-v[now-1]);
      v.erase(now);
      now--;
      k--;
      continue;
    }
    ll tmp=min(abs(v[now]-v[now-1]),abs(v[now]-v[now+1]))
    if(abs(v[now]-v[now-1])<abs(v[now]-v[now+1])){
      now--;
      v.erase(now+1);
    }
    else{
      now++;
      v.erase(now-1);
    }
    ans+=tmp;
    k--;
  }
  cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:33:14: error: no matching function for call to 'std::vector<long long int>::erase(int)'
   33 |       v.erase(0);
      |       ~~~~~~~^~~
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_vector.h:1536:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(const_iterator) [with _Tp = long long int; _Alloc = std::allocator<long long int>; iterator = std::vector<long long int>::iterator; const_iterator = std::vector<long long int>::const_iterator]'
 1536 |       erase(const_iterator __position)
      |       ^~~~~
/usr/include/c++/14/bits/stl_vector.h:1536:28: note:   no known conversion for argument 1 from 'int' to 'std::vector<long long int>::const_iterator'
 1536 |       erase(const_iterator __position)
      |             ~~~~~~~~~~~~~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1564:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(const_iterator, const_iterator) [with _Tp = long long int; _Alloc = std::allocator<long long int>; iterator = std::vector<long long int>::iterator; const_iterator = std::vector<long long int>::const_iterator]'
 1564 |       erase(const_iterator __first, const_iterator __last)
      |       ^~~~~
/usr/include/c++/14/bits/stl_vector.h:1564:7: note:   candidate expects 2 arguments, 1 provided
a.cc:40:14: error: no matching function for call to 'std::vector<long long int>::erase(int&)'
   40 |       v.erase(now);
      |       ~~~~~~~^~~~~
/usr/include/c++/14/bits/stl_vector.h:1536:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(const_iterator) [with _Tp = long long int; _Alloc = std::allocator<long long int>; iterator = std::vector<long long int>::iterator; const_iterator = std::vector<long long int>::const_iterator]'
 1536 |       erase(const_iterator __position)
      |       ^~~~~
/usr/include/c++/14/bits/stl_vector.h:1536:28: note:   no known conversion for argument 1 from 'int' to 'std::vector<long long int>::const_iterator'
 1536 |       erase(const_iterator __position)
      |             ~~~~~~~~~~~~~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1564:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(const_iterator, const_iterator) [with _Tp = long long int; _Alloc = std::allocator<long long int>; iterator = std::vector<long long int>::iterator; const_iterator = std::vector<long long int>::const_iterator]'
 1564 |       erase(const_iterator __first, const_iterator __last)
      |       ^~~~~
/usr/include/c++/14/bits/stl_vector.h:1564:7: note:   candidate expects 2 arguments, 1 provided
a.cc:45:15: error: 'min' cannot be used as a function
   45 |     ll tmp=min(abs(v[now]-v[now-1]),abs(v[now]-v[now+1]))
      |            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~