Hostel visit problem


sir please check where am i wrong

hello @Shivanchal-Agarwal-2530139037020445

using max heap u can answer kth smallest in O(1). so use max heap in place of min heap.

also use long long for distance .

approach ->
image

code->

no not heighest but kth smallest.
because we are always maintaining our heap size equal to k.
if we are finding any hostel whose distance is smaller than current kth smallest(i.e pq.top())
then we are popping current kth smallest from the heap and pushing the new hostel in place of that.

do a dry on pen and paper u will get the idea

thank you sir got it