Under construction

Still being built. Things may change

Strategies

Time limit1sMemory limit128 MB

Summary
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 3030 to 14401440) and the number of problems (from 33 to 2424).
  • The second line contains that many integers, the difficulties of the problems — how many minutes (from 11 to 600600) it takes to solve each one.

Output

For each scenario, first print a line Scenario #i:, where ii is the scenario number starting from 11. 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 00 or 11 problems). Separate consecutive scenarios with a single blank line.

Examples3

  1. Example 1

    Input
    2
    180 6
    23 42 170 33 7 19
    60 2
    43 17
    
    Expected output
    Scenario #1:
    Steve wins with 5 solved problems and a score of 288.
    
    Scenario #2:
    Steve wins with 2 solved problems and a score of 77.
    
  2. Example 2

    Input
    1
    1440 3
    10 20 30
    
    Expected output
    Scenario #1:
    Steve wins with 3 solved problems and a score of 100.
    
  3. Example 3

    Input
    1
    30 3
    50 60 70
    
    Expected output
    Scenario #1:
    Steve wins with 0 solved problems and a score of 0.