Here is my code for this problem — http://codeforces.net/contest/749/problem/D from Div-2 D round #388 Here is my submission --> http://codeforces.net/contest/749/submission/23178341 My code is well commented and as per the editorial given. It is taking too much time. The complexity is O(nlog(n)). How do I optimize my code? What operation/operations are taking too long ? Please Help! Thanks in advance.