Loading...
Loading...
Loading...
A courier is at the origin (0, 0). There are n delivery points. Print the k points closest to the origin by straight-line distance. If two points are equally far, the one with the smaller x comes first, then the one with the smaller y. Print each point as x y, nearest first.
x y.Example 1
Input
5 2 3 3 5 -1 -2 4 1 1 0 2
Output
1 1 0 2
Squared distances are 18, 26, 20, 2 and 4.
Example 2
Input
2 1 1 0 0 1
Output
0 1
Try the problem first. Open one hint at a time.
Compare squared distances x * x + y * y. No square root is needed.
A key of (distance, x, y) puts ties in the required order.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor