Under construction

Still being built. Things may change

Perfect Game

Time limit5sMemory limit512 MB

Summary
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 TT. Each of the TT test cases follows on three lines.

The first line of a test case contains the number of levels NN. The second line contains NN space-separated integers LiL_i. LiL_i is the number of seconds one attempt at level ii takes, whether you clear it or die. The third line contains NN space-separated integers PiP_i. PiP_i is the percent chance that one attempt at level ii kills you.

Levels are numbered from 00 to N−1N-1.

Limits

  • 1≤T≤1001 \le T \le 100
  • 1≤N≤10001 \le N \le 1000
  • 1≤Li≤1001 \le L_i \le 100
  • 0≤Pi<1000 \le P_i < 100

Output

For each test case, print one line containing Case #x: followed by NN space-separated integers. Here xx is the test case number, starting from 11.

The jjth integer is the number of the level you attempt jjth. The printed sequence must be a permutation of 00 to N−1N-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.

Examples3

  1. Example 1

    Input
    3
    4
    1 1 1 1
    50 0 20 20
    3
    100 10 1
    0 50 0
    3
    100 80 50
    40 20 80
    
    Expected output
    Case #1: 0 2 3 1
    Case #2: 1 0 2
    Case #3: 2 0 1
    
  2. Example 2

    Input
    1
    1
    1
    0
    
    Expected output
    Case #1: 0
    
  3. Example 3

    Input
    1
    5
    100 1 50 7 42
    0 0 0 0 0
    
    Expected output
    Case #1: 0 1 2 3 4