Please explain!

Can somebody please explain the approach to the problem
https://www.codechef.com/ALKH2016/problems/VLB