problem in finding the solution

I am trying to solve this problem ( https://kth.kattis.scrool.se/problems/zbrka ) for sometimes. But I don’t have any clue how to solve this problem. Can anyone please explain how to solve this problem.

Thanks in advance for your help.

this problem is somewhat related…http://www.codechef.com/problems/INSOMA3 !!!

it is done using merge sort…the aim of the above code is (in relation with the above ques) to calc the confusion…hope this helps…:slight_smile:

//