


The distance between two points on a plane is the Euclidean Distance.
If N = 2, K = 1 and the points are {2,3}, {-1, 2}.
Then the distance of the first point from the origin is sqrt((2 - 0) ^ 2 + (3 - 0) ^ 2) = sqrt(13).
The distance of the second point from the origin is sqrt((-1 - 0) ^ 2 + (2 - 0) ^ 2) = sqrt(5).
Can you solve this in O(N log K) time complexity?
The first line contains an integer 'T' which denotes the number of test cases or queries to be run. Then, the 'T' test cases follow.
The first line of each test case contains two integers 'N' and 'K' separated by a single space.
The second line of each test case contains 2 * N space-separated integers where for each i = 1 to 'N', the (2 * i - 1) th and the (2 * i) th element represents the x-coordinate and y-coordinate of ith point respectively.
For each test case, print a single line containing 2 * K space-separated integers where for each i = 1 to 'K', the (2 * i - 1) th and the (2 * i) th element represents the x-coordinate and y-coordinate of the i th point respectively. Print the output in sorted order.
The output of each test case will be printed in a separate line.
You do not need to print anything or sort the final result. It has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= K <= N <= 10 ^ 4
-10 ^ 4 <= POINTS[i][0], POINTS[i][1] <= 10 ^ 4
Time limit: 1 sec.
bool compare(point1, point2):
Instead of sorting all the points like in the previous approach, we create a custom heap of size K and push the distances of the points along with their index in the input array. Whenever the size of the heap exceeds K, we remove a point from the heap.