← 返回 snapchat 的题目列表K Closest Points to Origin (N log K)
类型:online_judge
Given a 2D integer array points where points[i] = [xi, yi] represents a point on the plane, and an integer K, return the K points closest to the origin (0,0) (Euclidean distance).
Requirements:
Your solution must run in O(N log K) time.
If multiple points have the same distance, any order is acceptable.
Input (stdin)
Line 1: integer N (number of points)
Next N lines: two integers xi yi
Last line: integer K
Output (stdout)
Print K lines, each as xi yi.
Constraints
1 <= K <= N <= 2 * 10^5
-10^4 <= xi, yi <= 10^4
Example Input:
5
1 3
-2 2
5 8
0 1
-1 -1
2
One valid output:
-2 2
0 1
Example
Input
5
1 3
-2 2
5 8
0 1
-1 -1
2
Output
-2 2
0 1