Help me in solving MAXDIFF problem

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

@kjha1893
like for ex:-
1 2 3 4 5 and k to be 4 your code will print 5 son will pick 1 2 3 4 and father will pick 5 but if father will pick 2 3 4 5 and som will pick 1 then answer would be 13 which will be the optimal one