var arr = '';
process.stdin.on('data',function(chunk){
arr += chunk;
});
process.stdin.on('end',function(){
arr = arr.split('\n');
let t = parseInt(arr[0]),i=1,line=1,n,k,nk,weights,a,son_weight,father_weight,j;
while(i<=t){
nk = arr[line++].split(' ');
n = parseInt(nk[0]);
k = parseInt(nk[1]);
weights = arr[line++].split(' ');
a = [];
for(j=0;j<weights.length;j++){
a[j] = parseInt(weights[j]);
}
a.sort((a, b) => a - b);
son_weight = 0;father_weight = 0;
for(j=0;j<n;j++){
if((j+1) <= k) son_weight = son_weight + a[j];
else father_weight = father_weight + a[j];
}
if(father_weight > son_weight) console.log(father_weight - son_weight);
else console.log(son_weight - father_weight);
i++;
}
})
Can anyone let me know for which test case i might be failing?