Difiiculty in understanding question's solution

This is the question

here is the solution
https://discuss.codechef.com/problems/MAXEP