Implementation for WEIRDFN on SPOJ using Red black tree giving TLE

I implemented WEIRDFN on SPOJ link(SPOJ.com - Problem WEIRDFN) using red-black trees which is much similar to Codechef problem RRATING which got AC using same implementation . How much difference can come if using priority queue or heaps instead of red black trees if in all cases (correct me if i am wrong) query can be satisfied in log n time ?? WHY time limit is exceeding for RB tress while its getting AC using heaps??

huhh… 25 views and still no answer :confused: Didn’t expect such a cold response from the coders to a beginner :/…