Please explain the output of this question. How can the distance equal be to 200 in the first case and then 162 and 98?
Output explanation Hostel Visit
rocket distance is calculated as xx+yy
so when type-2 occurs
the top of the heap will have 200(1010+1010)
and then when another type 2 query occurs we have 81 at the top(99+99)
and for the third tym 98 at the top(77+77)
logic is like 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.
Hi, Thankyou for the explanation . Please check why this code . Its working fine for the sample test case but both the hidden test cases failed.
Sir, please reply. I am stuck here.
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.
https://ide.codingblocks.com/s/106988 Please check for the mistake in this code. Ma’am according to my understanding of the question, i think the output for the sample test case shoudl me 200 162 ans 128. I could not understand why 98 is printed. Please explain that. And also, on submitting this code I got run-time error.
hi samriddhi
you can refer this
for your understanding