Help me in solving SWAPNUM31 problem, I'm getting SIGABRT error in first 4 test cases while last 3 a

My issue

My code

#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
	// your code goes here
	int t;cin>>t;
	while(t--){
	    int n,k;
	    cin>>n>>k;
	    
	    vector<long int> l(n);
	    
	    for(int i=0;i<n;i++){cin>>l[i];}
	    
	    if(n>2*k){
	        sort(l.begin(),l.end());}
	   else{
	       vector<long int> l1(2*(n-k));
	       
	       for(int i=0;i<n-k;i++){
	           l1[i]=l[i];
	           l1[2*n-2*k-i-1]=l[n-i-1];
	       }
	       
	       sort(l1.begin(),l1.end());
	       
	       for(int i=0;i<n-k;i++){
	           l[i]=l1[i];
	           l[n-i-1]=l1[2*n-2*k-i-1];
	           
	       }
	       
	       
	   }
	   for(auto i:l){
	       cout<<i<<" ";}
	       cout<<endl;
	    
	    

	   }
	return 0;
}

Problem Link: SWAPNUM31 Problem - CodeChef