

The first line of input contains an integer ‘T’ denoting the number of test cases.
The first line of the test case consists of two integers ‘n’ indicating a number of points and 'k'.
The next line ‘n’ lines consist of 2 space-separated integers 'xi' and 'yi', such that 'xi' is x-coordinate and 'yi' is y-coordinate of the 'ith' point.
Return the list of 'k' points. Return the list in ascending order of distance from the origin. Such that the one with minimum distance will be first. If two points have the same distance then one with a minimum x-coordinate will be first.
Print the output of each test case in a separate line.
1 <= ’T ’<= 10
1 <= ’n’ <= 10^6
1 <= ’k’ <= ’n’
-10^6 <= xi, yi <= 10^6
Can you solve the problem in time complexity better than O(NlogN)?
This approach is similar to quick sort. Using this approach, we will try to sort the first K element in their respective places.
We have created a function quickSelection(points, l, r, k), where points are the given array, k is the given integer, l and r is the current range in which we are trying to sort the elements.
During partition, we have selected the last element as the pivot element. We will try to find the correct position of the pivot element, and we will return the pivot index.
The main idea is to sort the points according to the distance and the conditions.
The algorithm is as follows:
The main idea is to use max priority queue then extract the topmost k elements.
The top of the priority queue will store point with maximum distance and maximum x-coordinate among the maximum distance.
The algorithm is as follows: