Finding median in a runnning stream

Question link:https://www.spoj.com/problems/RMID/
answer link:https://ide.codingblocks.com/s/54589
Sir please tell why the code is showing TLE.
Prateek Sir told this question from Spoj, hence spoj’s link.