Getting WA - unable to understand why-MAXDIFF- Mock Exam-1- CCDSAP

https://www.codechef.com/FLMOCK01/problems/MAXDIFF

Hello,

I think this is a pretty simple question, and the solution that i have come up with is - store the weights in an array, sort them in ascending, pick the first K for the kid; add them; the remaining n-k go to the dad, add them- find the diff and thats the answer. Can someone please point out where am i going wrong?

here is the code for your reference -
/* package codechef; // don’t place package name! */

import java.util.;
import java.lang.
;
import java.io.*;

/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{

public static void main (String[] args) throws java.lang.Exception
{
	// your code goes here
	int numTestCases;
	Scanner sc = new Scanner(System.in);
	numTestCases = sc.nextInt();
	while(numTestCases>0)
	{
	   int n,k;
	   n= sc.nextInt();
	   k = sc.nextInt();
	   int a[] = new int[n];
	   for(int i=0;i<n;i++){
	       a*=sc.nextInt();
	   }
	   Arrays.sort(a);
	   int sumk=0;
	   int sumDad=0;
	   for(int i=0;i<k;i++){
	       sumk= sumk + a*;
	   }
	   for(int i =k; i<n;i++){
	       sumDad = sumDad + a*;
	   }
	   int maxDiff=0;
	   maxDiff = sumDad-sumk;
	   System.out.println(maxDiff);
	numTestCases--;
	}
}

}

5 4

8 4 5 2 10

Your output is 9 but the correct output is 25. Hope you can find and fix the error by yourself now.

yes, realised my mistake, thanks a lot :slight_smile: