Problem 870
Fair Candy Swap
Easy · 10 pts · Array, Hash Table, Binary Search
Problem
Alice and Bob each have some boxes of candy. They want to swap exactly one box each so that afterwards both have the same total. If Alice gives a box of size x and receives one of size y, they need x - y = (sumA - sumB) / 2. Print the sizes x and y; if several swaps work, choose the smallest x (y is then fixed). Put Bob's box sizes in a set and check every Alice box.
Input
The first line contains N and M. The second line contains Alice's N box sizes. The third line contains Bob's M box sizes. At least one fair swap exists.
Output
Print the size Alice gives and the size Bob gives, separated by a space.
Constraints
1 <= N, M <= 10000; 1 <= sizes <= 100000
Example input
2 2 1 1 2 2
Example output
1 2
Explanation
Alice has 1 1 (total 2) and Bob has 2 2 (total 4). Swapping Alice's 1 for Bob's 2 gives both a total of 3, so the answer is 1 2.