Can anyone first please explain the language of output what we need to do if it is printing the k nearest points on each 2 why only the output is there once ,
Also check the code below
Hotel Visit - WA
in this ques you have to print the kth nearest distance whenever the user enters 2…create a max heap of size k(this can be done by pushing first k distances directly in the heap and after that check the distance at the top(max distance) with the current distance…only when current distance is less than your max distance pop the topmost element and push your current distance)
dry run for the sample input:
9 3
1 10 10 //push in heap as the heap size is less than k
1 9 9 //push in heap as the heap size is less than k
1 -8 -8 //push in heap as the heap size is less than k
2 //heap-{200,162,128} display heaps top
1 7 7 //as distance is 98 so pop the topmost element and push 98…heap-{162,128,98}
2-heap-{162,128,98} display heaps top
1 6 6 //as distance is 72 so pop the topmost element and push 72…heap-{128,98,72}
1 5 5 //as distance is 50 so pop the topmost element and push 50…heap-{98,72,50}
2-heap-{98,72,50} display heaps top
i have modified your code:
https://ide.codingblocks.com/s/72467
@Bhatia-Eklavya-120337398873287
Since the question is asking for nearest distance then shouldn’t it pop 128 when first 2 ( 200,162,128) is encountered ?