My solution is the same as the solution in the editorial and it works for the example testcases, can anyone please tell me where did the code go wrong

Consider test case:

1

5 3

10 8 4 5 2

Answer: 17.

Explanation: Items carried by kid is min(k,n-k).

In this case kid will carry only two items.

I think there is a typo in your testcase, correct me if I am wrong,

K is the no of items carried by the kid and in your case you have given me 3 items so, the kid should carry 3 items.

If I modify your testcase as

1

5 2

10 8 4 5 2

I get 17.

I am not able to get where did I make a mistake.

If I use

1

5 3

10 8 4 5 2

I get 7

No read the problem more carefully.

We are dividing total items into two groups one group contain k items, other n-k items.

Kid will carry one with lesser weight.

In my test case kid will carry only two items [4,2]. Father will carry three items [10,8,5].