Heap being formed is wrong through the approach given in videos

I am using the same array list approach, with upheafipy, but the heap being formed is wrong, it would be really helpful if you help me out here.

please share your code by saving it on ide.codingbloccks.com

I have submitted the solution on the platform itself as the link for discussion forum isnt working. Please do check. Thanks!

Hii please do look into this problem, What can i change to make it right?

use priority queue .it ll easily pass all the test cases .
refer to this

I successfully implemented the solution provided by you, but still could you help me figure out why we didn’t use the heaps method here?

you can use heap . (max heap ) to answer query 2 efficiently as well

follow this->
For every query of type 1, insert elements until the size of the heap becomes ‘k’.
Then for every query of type 1 after reaching the size k for heap(max-heap) we will check if the current element is smaller than the root of the heap or not. If it is not smaller then we ignore it else we remove the root of the heap and push the new element in the heap. (What this will do is maintain a heap of size k which will contain k nearest coordinates for the dean) .
For every query of type 2 just print the root of the heap.

you don’t have to use arraylist here, also use long instead of int.