#P4530. [CTSC2006] 投篮游戏
[CTSC2006] 投篮游戏
Description
At university, there are many P.E. classes, and everyone can pick what they like. This semester, King chose basketball because the instructor is a very interesting person.
On the first day, the instructor announced the grading rules:
There are basketballs (). The instructor has written an integer on each ball in advance (not necessarily distinct, with absolute value less than ). There are baskets, and each basket has a counter displaying an integer. Before a student starts, all counters are initialized to .
During the assessment, a student will take shots in total: for each shot, choose any basketball and throw it into any basket. In the end, all balls must be used and each ball must be used exactly once, and every basket must be used at least once.
If a ball labeled with integer is thrown into a basket whose counter currently displays , then that basket’s counter changes from to .
A student’s raw score is defined as the sum of the counters’ displayed values. The larger is, the higher the final grade the instructor will assign (in fact, the instructor grades by ranking using a normal distribution, but that is beyond the scope of this problem).
King is a sharpshooter and guarantees every shot goes in. However, King is bad at math and does not know how to arrange the shots to maximize his raw score. Can you help him?
Input Format
Multiple testcases. Each testcase consists of two lines:
- The first line contains two integers .
- The second line contains integers separated by spaces, which are the integers written on the basketballs.
The input ends with a line containing 0 0. There are at most testcases in a file.
Output Format
For each testcase, output one line containing an integer , the maximum possible raw score.
10 2
0 -1 -2 0 1 2 3 2 10 1
10 3
0 -1 -2 0 1 2 3 2 10 1
0 0
240
241
Hint
-
Constraints:
- .
- Exactly of the testcases satisfy .
-
Notes:
- may exceed any basic integer type.
- may also be less than .
-
Sample Explanation:
- The first testcase has multiple solutions; one solution is: .
- The second testcase has multiple solutions; one solution is: .
Translated by ChatGPT 5
京公网安备 11011102002149号