Reorder

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

문제

You are given NN numbers – v_1,v_2,,v_Nv\_1, v\_2, \dots , v\_N, and an integer AA. You can do an unlimited number of swaps in the array by swapping v_iv\_i and v_i+1v\_{i+1} for a cost of v_i+v_i+1v\_i + v\_{i+1}. The new array after the swap would then be v1,,v_i+1,v_i,,v_Nv1, \dots , v\_{i+1}, v\_i , \dots , v\_N. For a certain number RR, your task it to find the minimum sum of the costs of your swaps and (v_1+v_2++v_R)×A(v\_1 + v\_2 + \cdots + v\_R) \times A. Given QQ queries and an R_iR\_i for each of them, find the minimum cost you can achieve for each query. All queries are independent.

입력

There are 33 integers on the first line: NN – the size of the array, QQ – the number of queries and AA – the coefficient (v_1+v_2++v_R)(v\_1 + v\_2 + \cdots + v\_R) is multiplied by. The second line of the input contains NN positive integers v_1,v_2,,v_Nv\_1, v\_2, \dots , v\_N - the starting array. The last line holds the positive integers R_1,,R_QR\_1, \dots , R\_Q.

출력

On each of the QQ lines output the minimum cost for the corresponding query.

제한

  • 1Q,R_iN1 ≤ Q, R\_i ≤ N
  • 1v_i,A1061 ≤ v\_i , A ≤ 10^6

힌트

Example №1: It is optimal to not swap any elements. The cost is then (4+1)×5=25(4 + 1) \times 5 = 25.

Example №2: We can first swap 44 with 11 and then 44 with 22:

  • 4\color{red}{4} 1\color{red}{1} 22 33
  • 11 4\color{red}{4} 2\color{red}{2} 33
  • 11 22 44 33

The costs of the swaps are 4+1=54 + 1 = 5 and 4+2=64 + 2 = 6. Therefore, the total cost is

5+6+(1+2)×6=295 + 6 + (1 + 2) \times 6 = 29.