Hostel Visit - TLE

You are adding more and more elements in priority queue. You need to add just k elements.
What you can do is that if query is of type 1 then check the size of priority queue. If the size is less than k just insert the element otherwise check whether top element is greater than the current element,if yes, pop the top element and insert the new element otherwise do nothing.

I tried that logic, but there seems to be some error. Please help.

You should use max heap. Why are you using min heap? In max heap largest element is at top. Since largest element is to be removed you should use max heap.

For help you can see the code:

So, I’ve made changes and it works, but it is still failing one test case.
Just help me identify the error.

Use long long datatype instead of int.