Strategies
Time limit1sMemory limit128 MB
Given contest time and problem times, simulate three orderings (input, ascending, descending) and pick the winner by problems solved, then score, then Steve.
- Level
Easy3 of 10
- Topics
- Simulation, Sorting, Greedy
- Solved
- No attempts yet
Problem
Bill, Steve, and Linus take part in programming contests, just like the one you are competing in right now. They use different strategies, and we would like to find out whose strategy is best.
Bill simply solves the problems in the order the organizers hand them out. Steve first reads every problem and then solves them in increasing order of difficulty. Linus also reads every problem first, but he is ambitious and solves them in decreasing order of difficulty.
The difficulty of a problem is the number of minutes it takes to solve it. We have gathered statistics, so we know for every problem exactly how long it takes. All three always need the same amount of time on a given problem (that time depends only on the problem's difficulty); they differ only in the order in which they work.
For each contest, report the winner, how many problems that person solved, and their score. The score of a single problem is the number of minutes from the start of the contest until the moment it is solved. Each contestant solves problems one after another in their chosen order and stops as soon as the next problem could not be finished within the contest time. The total score is the sum of the scores of all solved problems. Nobody ever makes a mistake, so there are no penalties.
The winner is the contestant who solved the most problems. If several are tied on the number solved, the one with the lowest score wins. If there is still a tie, Steve wins, because he always brings delicious apple pie.
Input
The first line contains the number of scenarios. Each scenario describes one contest.
- The first line of a scenario contains two integers: the length of the contest in minutes (from to ) and the number of problems (from to ).
- The second line contains that many integers, the difficulties of the problems — how many minutes (from to ) it takes to solve each one.
Output
For each scenario, first print a line Scenario #i:, where is the scenario number starting from . Then print a single line stating who wins, how many problems that person solves, and their score, using exactly the format shown in the examples (keep the same wording even when the winner solves or problems). Separate consecutive scenarios with a single blank line.