There is a local brewery which produces wine. The wine production in this brewery is special. It happens over a period of N minutes.
In the ith minute, ith ingredient can be added with a cost of ci.
The catch here is that to add the ith ingredient, some (at least one) of the ingredients must have been at or after vi'th moment of time otherwise a bad reaction occurs and the wine is spoiled.
For example if vi for i=10 is 4 it means that you should have added some (at least one) of the ingredients between time=4 and time=9 (both inclusive) to add this(10
th) ingredient.
Now there is a long queue of Q customers.Each customer has a favourite ingredient ai. Each customer wants to know the minimum cost of wine such that it has its favourite ingredient.
Output the minimum cost of wine for each customer.
Note you can choose to stop adding ingredients at any point of time. For each customer the wine is produced independently.
Note: If vi==i, then no ingredient needs to be necessarily added before adding i'th ingredient.
INPUT
N Q
N spaced integers denoting ci(the cost array denoting ci)
N spaced integers denoting vi(the array denoting vi)
Q spaced integers denoting ai
Constraints
1<=N<=1000000
1<=ci<=2000000000
1<=vi<=i
1<=Q<=100000
1<=ai<=N
OUTPUT
The minimum cost of producing wine for each customer on a new line.
For the first person to add 3rd ingredient you have to necessarily add 2nd ingredient and to add second ingredient you have to necessarily add 1st ingredient so total cost=2+5+3=10.
For the third person optimal way to create wine is add first ingredient,fourth ingredient and fifth ingredient.