Nearest points
Limits: 2 sec., 256 MiB
This statement was translated automatically from Ukrainian.
There are \(n\) points on the plane numbered from \(1\) to \(n\) with coordinates \((x_i, y_i)\).
The distance between points with indices \(i\) and \(j\) is defined as \(dist(i, j) = min(|x_i-x_j|, |y_i-y_j|)\).
Find a pair of points with the smallest possible distance.
Input
The first line contains \(n\) — the number of points on the plane. The next \(n\) lines each contain 2 integers \(x_i\) and \(y_i\) — the coordinates of the \(i\)-th point.
Output
In a single line, print two integers separated by a space \(i\) and \(j\) — the indices of the points with the minimum distance.
If there is more than one such pair of points, find the pair that minimizes \(i + j\).
If there are still multiple such pairs, find the pair with the minimum \(i\).
Constraints
\(2 \le n \le 100000\),
\(-10^9 \le x_i, y_i \le 10^9\).
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 2 1 1 2 2 | 1 2 |
| Input (stdin) | Output (stdout) |
|---|---|
| 4 3 3 2 0 0 2 0 0 | 2 4 |
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|