Fruits

아직 제출이 없습니다시간 제한1초메모리 제한1024 MB

문제

Supermarkets usually have fruits for sale in sections, where each section is dedicated to a single type of fruit. The supermarket that Benson the Rabbit is visiting has NN sections and NN types of fruits. The sections are numbered from 11 to NN and each fruit is numbered from 11 to NN.

The iith fruit has tastiness ii and cost C_iC\_i. It is guaranteed that C_iC_jC\_i ≤ C\_j for all 1i<jN1 ≤ i < j ≤ N.

Each of the NN sections is to be assigned a distinct type of fruit. At the moment, the type of fruit assigned to section jj is A_jA\_j. If A_j=1A\_j = -1, then section jj is empty. Otherwise, fruit A_jA\_j is already assigned to section jj. Once all NN fruits have been assigned, the supermarket will open and Benson will enter the supermarket to buy the fruits.

Benson is very picky but also in a rush, so he will visit the sections in increasing order. Benson’s basket is initially empty, and when he reaches a section, he will compare the tastiness of the fruit in that section to the tastiness of all of the fruits in his basket. If his basket is empty, or if the tastiness of the fruit at the current section is greater than the tastiness of every other fruit in his basket, Benson will add that fruit to his basket.

To maximise revenue, you have been tasked with assigning the fruits to the sections such that the sum of cost of fruits that Benson adds to his basket is maximised. As Benson is rushing for time, he might only visit the first few sections before going straight to the cashier. Help compute, for each kk from 11 to NN, the maximum possible revenue that can be achieved if Benson only visits the first kk sections given that the arrangement of fruits can change for different kk.

입력

Your program must read from standard input.

The input starts with a line with one positive integer NN.

The second line contains NN integers where the ith integer represents A_iA\_i.

The third line contains NN integers where the ith integer represents C_iC\_i.

출력

Your program must print to standard output.

The output should contain a NN integers on a single line. The kth one should be the maximum sum of costs that Benson will pay if the fruits are assigned optimally if he visits only the first kk sections.

제한

  • 1N400,0001 ≤ N ≤ 400\\,000
  • 1A_jN1 ≤ A\_j ≤ N or A_j=1A\_j = -1
  • 1C_i1091 ≤ C\_i ≤ 10^9
  • C_iC_jC\_i ≤ C\_j for all 1i<jN1 ≤ i < j ≤ N