Bro, thank you for your code. But your way of using heap will lead to $n^2logn$ time rather than nlogn, since you are using buildHeap in every iteration, and it is nlogn. The right method is to use heap with lazy delete to achieve O(nlogn) complexity.
Bro, thank you for your code. But your way of using heap will lead to$n^2logn$ time rather than nlogn, since you are using buildHeap in every iteration, and it is nlogn. The right method is to use heap with lazy delete to achieve O(nlogn) complexity.