Problems > Closest to the Origin

Closest to the Origin

Difficulty: 1100 3500 ms 128 MB

math geometry

Among N points, print the one closest to the origin (Euclidean). Break distance ties by smaller x, then smaller y.

Input: the first line has N; the next N lines each have x y.

Output: the winning point's coordinates.

Constraints:

  • 1 ≤ N ≤ 5×104
  • |coordinates| ≤ 106

Sample Tests

Input 1
3
3 4
1 2
-1 2
Output 1
-1 2
Input 2
1
0 0
Output 2
0 0

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.