works correct for sample test cases, but gives wrong answer for all test cases while submitting.
Dividing array wrong answer
Your logic for maximum difference is incorrect. In case of maximum you need to sort the array and divide it into two halves, now subtract the lower half from bigger half.
The code for max and min looks something like this.
ll mx=0,mn=0;
sort(a,a+n);
for(int i=0;i<n/2;i++)
{
mx+=(a[i+n/2]-a[i]);
mn+=(a[2*i+1]-a[2*i]);
}
1 Like