Can anyone provide a hint to this ques?

Codeforces Round #428 editorial - Codeforces problem 839D
In this question we have to partition the array according to some condition?But I cannot understand the formula used.