I have explained logic through comments. I am maintaining a min heap using priority queue. To get kth smallest i empty k-1 elements in a vector, get top element of heap and then put back the elements from the vector into the heap. But it is giving wrong answer and tle.
Wrong answer and TLE in Hostel Visit
I made that change. It is still not working. Thanks for replying!
t is type of query. According to question input there will be k queries and any number of insertions. So i keep track of number of queries i.e. whenever t=2 because i have to stop taking input after t=2 has occured k times.
@Aditya.Jethliya insertion is also a type of query. There are basically 2 types of queries, in type 1 you have to do insertion, and in type2 you have to give the kth nearest hostel
1 Like
Ohhh. So sorry. I got confused because sample case has 3 cases of t=2.
@Aditya.Jethliya its alright! correct your code accordingly now and let me know if you have any further doubts