Perfect Game
Time limit5sMemory limit512 MB
Find the level order that minimizes the expected time to clear every level in one deathless run when any death restarts the run from the first level.
- Level
Medium7 of 10
- Topics
- Greedy, Probability, Sorting
- Solved
- No attempts yet
Problem
You are playing a video game that gives you an achievement if you clear every level consecutively without dying. You may play the levels in any order you like, and each attempt at a level either clears it or kills you. Every level has a fixed chance of killing you and a fixed duration for one attempt. Dying in a level takes exactly as long as clearing it. As soon as you die, you start again from the first level of your chosen order.
Find the order of levels that minimizes the expected time to earn the achievement.
Note: failing a level kills only your character in the game, not you. Otherwise almost nobody would go after this achievement.
Input
The first line contains the number of test cases . Then test cases follow, each of which consists of three lines.
The first line of each test case contains the number of levels . The second line contains space-separated integers . is the number of seconds one attempt at level lasts, and it is the same whether you clear the level or die in it. The third line contains space-separated integers . is the percent chance that you die in any single attempt at level .
Limits
Output
For each test case, print one line starting with Case #x: , where is the case number starting from 1. After it print space-separated integers. The th integer is the index of the th level you attempt, and the order must minimize the expected time to earn the achievement. Level indices run from to .
If several orders give the same expected time, print the lexicographically least one. Between two orders, the one with the smaller index at the first position where they differ comes first lexicographically. Among many orders, the lexicographically least one is the order that is lexicographically smaller than every other order.