Codeforces 362C

Please tell me this problem.Problem - C - Codeforces
I am not able to solve it even after reading the editorial.