#P6024. 机器人

机器人

Description

Now, Xiao W wants the robot to help him complete nn tasks.

Each task has two attributes: the money needed to complete it wiw_i, and the success probability pip_i.

Xiao W needs to arrange the tasks in some order. Then, the robot will do the tasks in the following way:

  • Start from the first task.
  • After paying the cost to do task ii, if it succeeds, then continue to do task i+1i+1; otherwise, restart from the first task.
  • After successfully completing task nn, the process ends.

For example, when n=2n=2, one possible process is:

  • Do task 11, fail.
  • Do task 11, succeed.
  • Do task 22, fail.
  • Do task 11, succeed.
  • Do task 22, succeed.
  • Process ends, and the total cost is 3w1+2w23w_1+2w_2.

Now, Xiao W wants you, who are studying OI, to help him find an ordering that makes his expected cost as small as possible.

Input Format

The first line contains an integer nn, the number of tasks.

The next line contains nn integers w1,w2,,wnw_1,w_2,\cdots,w_n, as described above.

The next line contains nn integers P1,P2,,PnP_1,P_2,\cdots,P_n, where Pi=pi×104P_i=p_i\times10^4, and the meaning of pip_i is as described above.

Output Format

If it is impossible to complete the tasks no matter what, output one line with the string Impossible.

Otherwise, output one line with nn integers c1,c2,,cnc_1,c_2,\cdots,c_n, which is a permutation of 1,2,,n1,2,\cdots,n. This represents the task order: the ii-th arranged task is task cic_i in the input.

2
999 1
5000 10000

1 2
1
1
0

Impossible

Hint

Explanation for Sample 1: You can understand it intuitively. Since task 22 is guaranteed to succeed, putting it last is definitely not worse.

Explanation for Sample 2: Obviously, this task can never be completed, because its success probability is 00.

Note: Whether the task succeeds or not, you always have to pay the cost wiw_i to attempt it.


This problem uses SPJ\text{SPJ}. If your output is at least as good as the answer output (or both are Impossible), then you will get full score on this test point; otherwise, you will get 00 score on this test point.

For some reason, this problem does not provide the SPJ\text{SPJ} to contestants.


Constraints:
For 10%10\% of the testdata, 1n101\le n\le 10.
For another 20%20\% of the testdata, all wiw_i are equal.
For another 20%20\% of the testdata, all pip_i are equal.
For all testdata, 1n2×1051\le n\le 2\times10^5, 1wi1091\le w_i\le 10^9, 0Pi1040\le P_i\le10^4.

Translated by ChatGPT 5