Unneighbourly Plans
Ray and Justin are moving to Sydney and are picking places to stay. They don't like each other so they have decided to come together and pick places that are as far away as possible.
Help them pick a pair of houses from the possibilities that have the maximum Euclidean distance from each other. Euclidean distance is defined using Pythagoras' Theorem as .
Input
The first line contains a single integer . The next
lines each contain two integers separated by a space of the form
representing the coordinates of the
th place Ray is willing to live.
The same is repeated for Justin's properties; the next line contains a single integer . The next
lines similarly contain two integers separated by a space between
and
each representing the coordinates of each place Justin is willing to live at.
Output
Output the and
coordinates Ray should live at on one line, followed by the coordinates Justin should live at on the next line.
If there is a tie, use the point that occurs earliest in Ray's list. If there is still a tie, use the point that occurs earliest in Justin's list.
Hint: When calculating distances, it is possible for a regular 32-bit int to be overflown (). It is good practice to calculate and check these things generally in contests yourselves, but we'll tell you this time that you should use a bigger type like
long long
or int64_t
(C++).
Example 1
Input 1
2
10 5
5 7
2
1 3
4 2
Output 1
10 5
1 3
Explanation 1
The distance between and
is
. This is the furthest distance between any pair of properties in either list, so this is where they should choose to live.
Input 2
3
0 0
1 1
2 2
3
3 0
0 3
-1 2
Output 2
0 0
3 0
Explanation 2
It's evident that the maximum distance between any pair of properties is 3, but there are multiple pairs with this distance, so the tiebreaker should be used. The pairs with this distance are ,
, and
. As stated, we should use the point that occurs earliest in Ray's list, so out of
and
we will be picking
. However, there is still a tie, so we should use the point that occurs earlier in Justin's list - that being
.
Comments