Two logistics depots, North and South, each store a collection of sealed fuel canisters holding a known integer number of liters. The depot managers have agreed to swap exactly one canister from North for exactly one canister from South so that, after the exchange, the two depots hold exactly the same total amount of fuel. It is guaranteed that at least one such pair of canisters exists among the depots' current stock (the two totals may already be equal, in which case swapping two equal-valued canisters also counts as valid). Given the liter readings of every canister in both depots, report the liters of one canister from North and the liters of one canister from South that can be swapped to leave both depots with equal totals.
Print two space-separated integers: the liters of the chosen North canister followed by the liters of the chosen South canister. Any pair that equalizes the two totals after the swap is an acceptable answer.
Example 1
Input
3 1 2 5 2 2 4
Expected
5 4
Explanation
North totals 1+2+5=8 liters and South totals 2+4=6 liters. Swapping North's 5-liter canister for South's 4-liter canister gives North 8-5+4=7 liters and South 6-4+5=7 liters, so both depots end up equal. No smaller North canister (1 or 2) has a matching South partner that balances the totals.
Example 2
Input
3 6 1 9 2 2 4
Expected
9 4
Explanation
North totals 6+1+9=16 liters and South totals 2+4=6 liters. Neither North's 6-liter nor 1-liter canister has a South partner that balances the totals, but swapping North's 9-liter canister for South's 4-liter canister gives North 16-9+4=11 liters and South 6-4+9=11 liters, so both depots end up equal.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →