My issue
My code
#include <iostream>
#include<algorithm>
using namespace std;
int main() {
// your code goes here
int t,n,k;
cin>>t;
while(t--){
cin>>n>>k;
long long int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
// long int b[k],d[n-k];
long int sum1=0,sum2=0,j=k;
sort(a,a+n);
for(int i=0;i<k;i++){
sum1+=a[i];
}
for(;j<n;j++){
sum2+=a[j];
}
cout<<sum2-sum1<<endl;
}
return 0;
}
Problem Link: MAXDIFF Problem - CodeChef