題目重現
The ACM ICPC’s rule of scoring is as the following:
A problem is solved when it is accepted by the judges. Teams are ranked according to the most problems solved. For the purposes of awards, or in determining qualifier(s) for the World Finals, teams who solve the same number of problems are ranked by least total time. The total time is the sum of the time consumed for each problem solved. The time consumed for a solved problem is the time elapsed from the beginning of the contest to the submittal of the accepted run plus 20 penalty minutes for every rejected run for that problem regardless of submittal time. There is no time consumed for a problem that is not solved.
For example, if one has the following contest record:
- At the 100th minute submitted problem A, rejected;
- At the 140th minute submitted problem B, rejected;
- At the 150th minute submitted problem B, accepted;
- At the 160th minute submitted problem C, accepted.
Then his total time = (150+20) + 160 = 330. Notice that it took him only 10 minutes to finish problem C. Assume that he spent 40 minutes on reading all the problems through, then if he could do problem C first and problem A last, his contest record might look like:
- At the 50th minute submitted problem C, accepted;
- At the 90th minute submitted problem B, rejected;
- At the 100th minute submitted problem B, accepted;
- At the 160th minute submitted problem A, rejected.
Then his total time would be 50 + (100+20) = 170. Hence the order of solving the problems will affect one’s final rank.
Now suppose that you are in a one-person team. It will take you
Your task is to write a program to find yourself the order of solving the problems which gives you the best chance of winning the contest.
Input Specification
Each input file contains several test cases. For each test case, the 1st line contains 3 integers: the total number of contest hours H
(N
(N
lines each contains a problem’s name and a pair of positive integers H
signals the end of input.
Output Specification
For each test case, you are supposed to print to standard output the total time in a line in the format shown by the sample. Then print the names of the problems you will solve in the correct order, each name in a line. If there are several solutions, you must output the smallest sequence. A sequence of problems
Sample Input
2 3 40
A 60 10
B 40 10
C 10 20
2 3 40
Try_This_One 20 5
And_This_One 20 5
Then_This_One 20 5
-1
Sample Output
Total Time = 170
C
B
Total Time = 295
Try_This_One
And_This_One
Then_This_One
題目大意
按照ACM/ICPC的比賽計分規則(解題數+20分鐘罰時規則),給定比賽時間、總題數。
假設某個人是這樣做題的:
1. 用一定時間通讀所有的題,計算出解出每個題目所需的時間,以及如果錯了,調試一次所需的時間。
2. 他一旦開始做某題,不做出來就不換題(一不做二不休)。
3. 對於每道題,他第一次提交的時間決定了他需要調試的次數。
具體地說是這樣的:
- 開始1小時(包括1小時整)內提交一次AC;
- 第二個小時內提交需要調試一次才能AC;
- ……
- 第N個小時內提交需要提交N次才能AC;
問題是要幫他確定一個可以獲得儘量高排名的做題順序:在解題量儘量高的前提下讓罰時儘量小。
題目解法
對於
然而題目的規模不大,
完全模擬真實比賽進程就可以了,由此可以得到兩個基本的搜索出口:比賽時間到、題目全部解出(AK)。
每當到達搜索出口時,要將當前解與當前最優解比較並試圖更新(最優解合併),這裏需要
這個問題呢,僅以N爲因子則時間複雜度不可能降低,最優算法即