Im getting TLE for one of the test case https://ide.codingblocks.com/s/80307
Hostel visit question
q can be upto 10^5 and ur time complexity is q^2logq
so u will get a tle
hint—>try to do with priority queue
pop out an element if and only if there are k smaller elemets in the queue
use long long int instead of int because you are squaring a number and squares wont fit into int data structure.
secondly pop an element when size of queue is greater than k not equal to k.
watch this
i have just modified your code.
Can you explain your logic? I couldnt get why did you pop and element while printing and not while pushing
you can pop out the element while pushing also or you can pop out the element whenever you want , just the size of queue should not exceed k
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.