348. Closest Point
0
Medium
Your task is to find the m closest points to the origin on a cartesian plane. You are given an array of coordinates (X, Y) representing these points.
Input Format
The first line of input should contain two integers, n and m, representing the number of points and the number of closest points to find, respectively. The following n lines should each contain two integers, x[i] and y[i], representing the coordinates of a point.
Output Format
Output the points in sorted order based on their X-coordinate.
Example
Input
3 2
3 3
5 -1
-2 4
Output
-2 4
3 3
Constraints
1 <= m <= points.length <= 10^4
-10^4 < x[i], y[i] < 10^4
-10^4 < x[i], y[i] < 10^4
Loading...
View Submissions
Console