Wrestling Team Selection
InterviewTime limit1sMemory limit128 MB
Split up to 100 wrestlers into two teams of nearly equal size so the total weights differ as little as possible.
- Level
Medium5 of 10
- Topics
- Dynamic programming
- Solved
- No attempts yet
Problem
The national wrestling association is dividing its athletes into two teams for the upcoming Olympic trials.
Every athlete belongs to exactly one of the two teams. The sizes of the two teams differ by at most 1. Under those conditions, the difference between the two total weights must be as small as possible.
Given the weight of every athlete, divide them into teams as described and compute the total weight of each team.
Input
The first line contains the number of athletes . Each of the next lines contains the weight of one athlete, an integer that is at least and at most . The association has no more than athletes.
Output
Print the total weight of the two teams on one line, separated by a space. Print the smaller total first.