HOSTEL VISIT CPP


Whats wrong with this ? I am getting a wrong answer message

@Kush_1312 i see that your latest submission passed all the test cases.

I didn’t use heaps in that, I want a solution using heaps also

@Kush_1312 for heaps you should consider using priority_queue.
Now, in a heap only the top element is useful to us. rest of the elements are distributed randomly and its no guarantee that if v[0] gives largest element then v[k-1] will give you kth largest element. To extract kth largest element from a heap you have to do pop() operation k-1 times and then only the kth largest element will come on top.

But for a max heap of size k the largest element would only be the root !?

@Kush_1312 yes that’s correct.

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.