Language: C++

# include "iostream"
# include "cstdio"
# include "algorithm"

using namespace std;

const int maxm=1e5+10;

long long ans=1e9+10; 
long long N,K;
long long Stack1[maxm],Top1;
long long Stack2[maxm],Top2;
 
int main(){
	register int i;
	long long x; 
	scanf("%lld%lld",&N,&K); 
	for(i=1;i<=N;i++){
		scanf("%lld",&x);
		if(x<0){
			Stack1[++Top1]=-x; 
		}else{
			Stack2[++Top2]=x; 
		} 
	}
	sort(Stack1+1,Stack1+1+Top1);
	sort(Stack2+1,Stack2+1+Top2); 
	/*for(i=1;i<=Top1;i++){
		printf("%d ",Stack1[i]);
	}putchar('\n');
	for(i=1;i<=Top2;i++){
		printf("%d ",Stack2[i]);
	}*/ 
	for(i=0;i<=min(Top1,K);i++){
		if(K-i>Top2 || K-i<1) continue; 
		int a=Stack1[i]+Stack2[K-i]*2,b=Stack1[i]*2+Stack2[K-i];
		ans=min(ans,min(a,b)); 
	}
	printf("%lld",ans); 
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:15:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   15 |         register int i;
      |                      ^
a.cc:37:24: error: no matching function for call to 'min(long long int&, const int&)'
   37 |                 ans=min(ans,min(a,b));
      |                     ~~~^~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 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:37:24: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   37 |                 ans=min(ans,min(a,b));
      |                     ~~~^~~~~~~~~~~~~~
/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,
                 from a.cc:3:
/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:37:24: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   37 |                 ans=min(ans,min(a,b));
      |                     ~~~^~~~~~~~~~~~~~