Language: C++

#include <bits/stdc++.h>
using namespace std;
#define int long long;
vector<int>v;
vector<int>s;
signed main(){
	int n,k;
	int x[100000];
	cin>>n>>k;
	for(int i=0;i<n;i++)cin>>x[i];
	for(int i=n-1;i>=0;i--){
		if(x[i]<=0)v.push_back(x[i]);
		else s.push_back(x[i]);
	}
	reverse(s.begin(),s.end());
	int ans=1000000000;
	if(s.size()==0){
		cout<<v[k-1]<<endl;
		return 0;
	}
	if(v.size()==0){
		cout<<s[k-1]<<endl;
		return 0;
	}
	if(k==1){
		int o=abs(v[0]);
		int p=s[0];
		cout<<min(o,p)<<endl;
		return 0;
	}
	for(int i=0;i<v.size();i++){
		if(i==k)break;
		if(i==k-1)ans=min(ans,abs(v[i]*2));
      else if(k-i-2<s.size())ans=min(ans,(abs(v[i])*2)+s[k-i-2]);
      else break;
	}
	cout<<ans<<endl;
	return 0;
}

Compiler output:
a.cc:3:18: error: template argument 1 is invalid
    3 | #define int long long;
      |                  ^~~~
a.cc:4:8: note: in expansion of macro 'int'
    4 | vector<int>v;
      |        ^~~
a.cc:3:18: error: template argument 2 is invalid
    3 | #define int long long;
      |                  ^~~~
a.cc:4:8: note: in expansion of macro 'int'
    4 | vector<int>v;
      |        ^~~
a.cc:4:11: error: expected unqualified-id before '>' token
    4 | vector<int>v;
      |           ^
a.cc:3:18: error: template argument 1 is invalid
    3 | #define int long long;
      |                  ^~~~
a.cc:5:8: note: in expansion of macro 'int'
    5 | vector<int>s;
      |        ^~~
a.cc:3:18: error: template argument 2 is invalid
    3 | #define int long long;
      |                  ^~~~
a.cc:5:8: note: in expansion of macro 'int'
    5 | vector<int>s;
      |        ^~~
a.cc:5:11: error: expected unqualified-id before '>' token
    5 | vector<int>s;
      |           ^
a.cc: In function 'int main()':
a.cc:3:18: error: declaration does not declare anything [-fpermissive]
    3 | #define int long long;
      |                  ^~~~
a.cc:7:9: note: in expansion of macro 'int'
    7 |         int n,k;
      |         ^~~
a.cc:7:13: error: 'n' was not declared in this scope; did you mean 'yn'?
    7 |         int n,k;
      |             ^
      |             yn
a.cc:7:15: error: 'k' was not declared in this scope
    7 |         int n,k;
      |               ^
a.cc:3:18: error: declaration does not declare anything [-fpermissive]
    3 | #define int long long;
      |                  ^~~~
a.cc:8:9: note: in expansion of macro 'int'
    8 |         int x[100000];
      |         ^~~
a.cc:8:13: error: 'x' was not declared in this scope
    8 |         int x[100000];
      |             ^
a.cc:3:18: error: declaration does not declare anything [-fpermissive]
    3 | #define int long long;
      |                  ^~~~
a.cc:10:13: note: in expansion of macro 'int'
   10 |         for(int i=0;i<n;i++)cin>>x[i];
      |             ^~~
a.cc:10:17: error: 'i' was not declared in this scope
   10 |         for(int i=0;i<n;i++)cin>>x[i];
      |                 ^
a.cc:10:24: error: expected ')' before ';' token
   10 |         for(int i=0;i<n;i++)cin>>x[i];
      |            ~           ^
      |                        )
a.cc:10:25: error: 'i' was not declared in this scope
   10 |         for(int i=0;i<n;i++)cin>>x[i];
      |                         ^
a.cc:3:18: error: declaration does not declare anything [-fpermissive]
    3 | #define int long long;
      |                  ^~~~
a.cc:11:13: note: in expansion of macro 'int'
   11 |         for(int i=n-1;i>=0;i--){
      |             ^~~
a.cc:11:27: error: expected ')' before ';' token
   11 |         for(int i=n-1;i>=0;i--){
      |            ~              ^
      |                           )
a.cc:15:17: error: 's' was not declared in this scope
   15 |         reverse(s.begin(),s.end());
      |                 ^
a.cc:3:18: error: declaration does not declare anything [-fpermissive]
    3 | #define int long long;
      |                  ^~~~
a.cc:16:9: note: in expansion of macro 'int'
   16 |         int ans=1000000000;
      |         ^~~
a.cc:16:13: error: 'ans' was not declared in this scope; did you mean 'abs'?
   16 |         int ans=1000000000;
      |             ^~~
      |             abs
a.cc:18:23: error: 'v' was not declared in this scope
   18 |                 cout<<v[k-1]<<endl;
      |                       ^
a.cc:21:12: error: 'v' was not declared in this scope
   21 |         if(v.size()==0){
      |            ^
a.cc:3:18: error: declaration does not declare anything [-fpermissive]
    3 | #define int long long;
      |                  ^~~~
a.cc:26:17: note: in expansion of macro 'int'
   26 |                 int o=abs(v[0]);
      |                 ^~~
a.cc:26:21: error: 'o' was not declared in this scope
   26 |                 int o=abs(v[0]);
      |                     ^
a.cc:26:27: error: 'v' was not declared in this scope
   26 |                 int o=abs(v[0]);
      |                           ^
a.cc:3:18: error: declaration does not declare anything [-fpermissive]
    3 | #define int long long;
      |                  ^~~~
a.cc:27:17: note: in expansion of macro 'int'
   27 |                 int p=s[0];
      |                 ^~~
a.cc:27:21: error: 'p' was not declared in this scope
   27 |                 int p=s[0];
      |                     ^
a.cc:3:18: error: declaration does not declare anything [-fpermissive]
    3 | #define int long long;
      |                  ^~~~
a.cc:31:13: note: in expansion of macro 'int'
   31 |         for(int i=0;i<v.size();i++){
      |             ^~~
a.cc:31:23: error: 'v' was not declared in this scope
   31 |         for(int i=0;i<v.size();i++){
      |                       ^
a.cc:31:31: error: expected ')' before ';' token
   31 |         for(int i=0;i<v.size();i++){
      |            ~                  ^
      |                               )