Hi,

I m getting “Wrong answer” for this submission http://www.codechef.com/viewsolution/2059067 . Can anyone please help to check and tell me the reason as to why this is not being accepted. As I check at my end, the output and input format are exactly the same as required.

~Thanks for your time

never print anything except the output. You don’t have to make your program user friendly. Strictly follow the Output format.

and i added the line

if(k>(n-k)) k=n-k;

1 Like

@aichemzee, Thanks a lot for your help.

I get your point regarding the output formats, but I don’t understand why we need this line here.

if(k>(n-k)) k=n-k;

Can you explain a bit.

we need this line because if k gets larger than n/2 the other group (having n-k elements) will have lesser number of items. So to increase the difference you will have to choose n-k smaller elements in this group and the larger k elements in the other.

2 Likes