Order the levels to minimize the expected total play time when any death restarts the run from the first level.
Medium7GreedySortingProbabilityNo attempts yetTime limit5sMemory limit512 MBIn 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.
The first line contains the number of test cases T. Each of the T test cases follows on three lines.
The first line of a test case contains the number of levels N. The second line contains N space-separated integers Li. Li is the number of seconds one attempt at level i takes, whether you clear it or die. The third line contains N space-separated integers Pi. Pi is the percent chance that one attempt at level i kills you.
Levels are numbered from 0 to N−1.
For each test case, print one line containing Case #x: followed by N space-separated integers. Here x is the test case number, starting from 1.
The jth integer is the number of the level you attempt jth. The printed sequence must be a permutation of 0 to N−1 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.