Hi everyone,
i was trying to do Moscow Subregional yesterday (at Codeforces Gym) and got stuck at problem K (The Top K Elements). After some thinking, all i could get is an O(n) approach, n<=10^8, which "apparently", or maybe certainly, leads to TLE. Could someone give me a hint on this problem?
Thanks.
hint: radix sort
Yes, this problem should be solved in O(n). Operations in the solution are very simple, so quite many of them can fit into two seconds.
nth_element
Thank You very much! My own version of nth_element was not as good as algorithm's. Just calling nth_element saved a lot of time.
Is heap too slow? nlogk?