I'm trying to do MCHEF from codechef long july 2015 . I've tried to implement what is written in the editorial but i'm constantly getting tle , The complexity of my solution seems to be enough to pass the constraints.Why am i getting TLE?? help !!
LINK TO CODE- http://pastebin.com/T5ZxchXL
you are using long long datatype everywhere , you should switch to int wherever possible (final answer doesnt fit in int) , also you are using a set which is quite slow as compared to a priority queue , you should use a priority_queue . You can Have a look at my solution : https://www.codechef.com/viewsolution/7352983