math,ad hoc , binary search
problem link- I am not able to understand the editorial also .... help... its an interesting problem