need editorial for KOL16E

problem link:https://www.codechef.com/problems/KOL16E

could anyone explain the approach of solving the problem.