Can someone please explain how to solve this question http://codeforces.me/contest/814/problem/C within the given time limit. I have read the editorial but could not understand well because it was very brief.I would be thankful if someone explains this in a bit detail on how to solve. :)