Lonesome Partners
InterviewTime limit1sMemory limit128 MB
Given N points, find the 1-based indices of the two points with the largest Euclidean distance, guaranteed unique.
- Level
Easy3 of 10
- Topics
- Brute force, Geometry, Implementation, Array
- Solved
- No attempts yet
Problem
Bessie and the rest of the herd — cows in total () — have gone to a dance. During one part of the dance, two cows are chosen as the Belles of the Ball.
The organizer records the integer coordinates (, ) of every cow on the floor and asks you to find the indices of the two cows that are farthest apart. This farthest pair is guaranteed to be unique.
Distance is the ordinary Euclidean distance — the square root of the sum of the squares of the differences of the and coordinates:
For example, consider these eight cows placed on the floor (C marks a cow):
8 | . . C . . . . . . .
7 | . . . . . . . . . .
6 | . . C . . . . . . .
5 | . . . . C C . C . .
4 | . . . . . C . . . .
3 | . . . C . . . . . .
2 | . . . . . . . . . .
1 | . . . . . . . . . C
0 +---------------------
0 1 2 3 4 5 6 7 8 9
Here the two cows that are farthest apart are the one at and the one at .
Input
- Line 1: a single integer .
- Lines 2 to : line contains two integers and , the coordinates of cow .
Output
- One line with two integers: the 1-based indices of the two cows that are farthest apart, printed in increasing order and separated by a single space.
Hint
In the illustrated example the farthest-apart pair is cow (at ) and cow (at ), so their indices are printed as 3 7.