Lifeboat Balancing
Time limit1sMemory limit128 MB
Split all passengers into two boats with equal head counts (off by one when N is odd) so the two total weights differ as little as possible.
- Level
Medium6 of 10
- Topics
- Dynamic programming
- Solved
- No attempts yet
Problem
A large cruise ship with plenty of design flaws has begun to sink on its first voyage. Two lifeboats hang on the side, and each one holds half of the passengers. A lifeboat that carries far more weight than the other risks sinking, so the two loads have to be as close as possible.
All passengers must board a lifeboat, and both lifeboats must carry the same number of people. When is odd an even split is impossible, so one boat takes people and the other takes . Under that rule, report the two loads that make the difference between the boats as small as possible.
Input
The first line has , the number of test cases.
The first line of each test case has , the number of people who must board (). Each of the next lines has one passenger weight ().
Output
For each test case print the two loads of the most balanced distribution on one line. If the two loads differ, print the smaller one first. Separate the two numbers with a single space.