Perfect Game
Time limit5sMemory limit512 MB
Order the levels to minimize the expected total play time when any death restarts the run from the first level.
- Level
Medium7 of 10
- Topics
- Greedy, Sorting, Probability
- Solved
- No attempts yet
Problem
In a video game you earn an achievement by clearing every level in a row without dying once. You may play the levels in any order you like, and each attempt at a level either clears it or kills you. Each level has its own chance of killing you and its own duration for one attempt.
An attempt takes the same amount of time whether you clear the level or die in it. As soon as you die you start over from the first level of your chosen order.
Find an order of the levels that minimizes the expected time until you earn the achievement.
Input
The first line contains the number of test cases . Each of the test cases follows on three lines.
The first line of a test case contains the number of levels . The second line contains space-separated integers . is the number of seconds one attempt at level takes, whether you clear it or die. The third line contains space-separated integers . is the percent chance that one attempt at level kills you.
Levels are numbered from to .
Limits
Output
For each test case, print one line containing Case #x: followed by space-separated integers. Here is the test case number, starting from .
The th integer is the number of the level you attempt th. The printed sequence must be a permutation of to whose expected time to earn the achievement is the smallest possible.
If several orders reach that smallest expected time, print the lexicographically least one among them. Of two orders, the lexicographically smaller one has the smaller number at the first position where they differ.