题目描述
Problem Background
Xiao W has purchased a robot.
Problem Description
Now, Xiao W wants the robot to help him complete \( n \) tasks.
Each task has two attributes: the cost \( w_i \) required to complete it, and the success rate \( p_i \).
Xiao W needs to arrange the tasks in a certain order, after which the robot will perform the tasks in the following manner:
- Start with the first task;
- After spending the cost to complete the \( i \)-th task, if successful, continue with the \( i+1 \)-th task; otherwise, restart from the first task;
- After successfully completing the \( n \)-th task, the process ends.
For example, when \( n=2 \), a possible process is:
- Perform task 1, fail;
- Perform task 1, succeed;
- Perform task 2, fail;
- Perform task 1, succeed;
- Perform task 2, succeed;
- The process ends, with a total cost of \( 3w_1 + 2w_2 \).
Now, Xiao W hopes that you, an OI enthusiast, can help him find an arrangement order that minimizes his expected cost.
Input Format
The first line contains an integer \( n \), representing the number of tasks.
The next line contains \( n \) integers \( w_1, w_2, \cdots, w_n \), as described above.
The following line contains \( n \) integers \( P_1, P_2, \cdots, P_n \), where \( P_i = p_i \times 10^4 \), and \( p_i \) is as described above.
Output Format
If it is impossible to complete the tasks under any circumstances, output a single line containing the string Impossible.
Otherwise, output a single line containing \( n \) integers \( c_1, c_2, \cdots, c_n \), which is a permutation of \( 1, 2, \cdots, n \), indicating the arrangement order of the tasks, where the \( i \)-th task in the arrangement is the \( c_i \)-th task in the input.
Sample Input and Output
Sample Input #1
2
999 1
5000 10000
Sample Output #1
1 2
Sample Input #2
1
1
0
Sample Output #2
Impossible
Notes
Explanation of Sample 1: Intuitively, since task 2 is guaranteed to succeed, placing it last cannot be worse.
Explanation of Sample 2: Clearly, this task cannot be completed since its success rate is 0.
Note: The cost \( w_i \) is always incurred regardless of whether the task is successful or not.
This problem includes a Special Judge (SPJ). If your output is as optimal as the answer's output (or both are Impossible), you will receive full marks for this test case; otherwise, you will receive no points for this test case.
Due to certain reasons, the SPJ is not provided to the contestants.
Data Range
For 10% of the data, \( 1 \le n \le 10 \).
For another 20% of the data, all \( w_i \) are equal.
For another 20% of the data, all \( p_i \) are equal.
For all data, \( 1 \le n \le 2 \times 10^5 \), \( 1 \le w_i \le 10^9 \), \( 0 \le P_i \le 10^4 \).
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分