problem in solving "Maximum weighted difference"?

Can anyone tell why this to the problem Maximum Weighted Difference solution is incorrect.

Hi arpit,

you have done everything fine except one i.e. what would be the case when K > N/2 ?.
you are counting this case in favor of child weight but problem statement says one group has exactly K items not that group which is carried out by his son.
for K > N/2 take smaller group for his child i.e.
for( i=0 ; i< n-k; i++ ) child_weight+=weight[i];
for( i=n-k ; i< n ; i++) parent_weight+=weight[i];
and print ( parent_weight-child_weight ) no need of abs() function because we know the truth.

it is enough ? if you have doubt please comment :frowning: