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