I am trying to solve this problem http://codeforces.net/contest/652/problem/D. My approach is http://codeforces.net/contest/652/submission/18906153 which is nlogn and should pass the time constraint.However I am getting TLE. I think this might be due std::distance which i have used to calculate distance b/w 2 elements in set.Please HELP.