Can anyone provide a hint to this ques?

http://codeforces.com/blog/entry/53815 problem 839D
In this question we have to partition the array according to some condition?But I cannot understand the formula used.

//