Language: C++

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };



signed main() {
	ll n, k;
	vector<ll>x;
	vector<ll>mai, pu;
	vector<ll>mai2, pu2;


	cin >> n >> k;

	mai.push_back(0);

	for (int i = 0; i < n; i++) {
		ll num;
		cin >> num;
		x.push_back(num);
		if (num < 0) {
			mai.push_back(abs(num));
		}
		else {
			pu.push_back(num);
		}
	}

	ll sa = 0, minn = INF;

	if (pu.size() < k) {
		sa = abs(pu.size() - k);
	}
	
	sort(mai.begin(), mai.end());

	//for (int i = (sa==0 ? k - 1: pu.size() - 1), j = 0; i >= 0; i--, j++ ) {
	for (int i = (sa == 0 ? k - 1 : pu.size() - 1), j = 0; i >= 0 && j < mai.size(); i--, j++) {
		ll num = pu[i];
		ll num2 = mai[j + sa] * 2;
		minn = min(minn, num + num2);
		//cout << "i->" << i << " num->" << num << " num2->" << num2 << endl;
	}

	mai.erase(mai.begin());
	pu.insert(pu.begin(), 0);

	ll sa2 = 0;

	if (mai.size() < k) {
		sa2 = abs(mai.size() - k);
	}

	//for (int i = (sa2 == 0 ? k - 1 : mai.size() - 1), j = 0; i >= 0; i--, j++) {
	for (int i = (sa2 == 0 ? k - 1 : mai.size() - 1), j = 0; i >= 0 && j < pu.size(); i--, j++) {
		ll num = mai[i];
		ll num2 = pu[j + sa2] * 2;
		minn = min(minn, num + num2);
		//cout << "i->" << i << " num->" << num << " num2->" << num2 << endl;
	}


	cout << minn << endl;


	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:78:25: error: call of overloaded 'abs(long long unsigned int)' is ambiguous
   78 |                 sa = abs(pu.size() - k);
      |                      ~~~^~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/cstdlib:79,
                 from /usr/include/c++/14/bits/stl_algo.h:71,
                 from /usr/include/c++/14/algorithm:61,
                 from a.cc:3:
/usr/include/stdlib.h:980:12: note: candidate: 'int abs(int)'
  980 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
      |            ^~~
In file included from /usr/include/c++/14/cstdlib:81:
/usr/include/c++/14/bits/std_abs.h:137:3: note: candidate: 'constexpr __float128 std::abs(__float128)'
  137 |   abs(__float128 __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:85:3: note: candidate: 'constexpr __int128 std::abs(__int128)'
   85 |   abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:79:3: note: candidate: 'constexpr long double std::abs(long double)'
   79 |   abs(long double __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:75:3: note: candidate: 'constexpr float std::abs(float)'
   75 |   abs(float __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:71:3: note: candidate: 'constexpr double std::abs(double)'
   71 |   abs(double __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:61:3: note: candidate: 'long long int std::abs(long long int)'
   61 |   abs(long long __x) { return __builtin_llabs (__x); }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:56:3: note: candidate: 'long int std::abs(long int)'
   56 |   abs(long __i) { return __builtin_labs(__i); }
      |   ^~~
a.cc:97:26: error: call of overloaded 'abs(long long unsigned int)' is ambiguous
   97 |                 sa2 = abs(mai.size() - k);
      |                       ~~~^~~~~~~~~~~~~~~~
/usr/include/stdlib.h:980:12: note: candidate: 'int abs(int)'
  980 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
      |            ^~~
/usr/include/c++/14/bits/std_abs.h:137:3: note: candidate: 'constexpr __float128 std::abs(__float128)'
  137 |   abs(__float128 __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:85:3: note: candidate: 'constexpr __int128 std::abs(__int128)'
   85 |   abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:79:3: note: candidate: 'constexpr long double std::abs(long double)'
   79 |   abs(long double __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:75:3: note: candidate: 'constexpr float std::abs(float)'
   75 |   abs(float __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:71:3: note: candidate: 'constexpr double std::abs(double)'
   71 |   abs(double __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:61:3: note: candidate: 'long long int std::abs(long long int)'
   61 |   abs(long long __x) { return __builtin_llabs (__x); }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:56:3: note: candidate: 'long int std::abs(long int)'
   56 |   abs(long __i) { return __builtin_labs(__i); }
      |   ^~~