아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Reorder

시간 제한2.5초메모리 제한1024 MB

요약
N개의 수로 이루어진 배열이 주어질 때, 각 R에 대해 인접한 원소를 교환하는 비용의 합과 앞 R개 원소 합의 A배를 더한 값이 최소가 되도록 만드는 문제를 Q개의 질의에 대해 해결한다.
난이도

보통10점 중 6점

유형
그리디, 정렬, 누적 합
정답자
아직 제출이 없습니다

문제

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.

제한

  • 1≤Q,R_i≤N1 ≤ Q, R\_i ≤ N
  • 1≤v_i,A≤1061 ≤ 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.

예제2

  1. 예제 1

    입력
    4 1 5
    4 1 2 3
    2
    
    예상 출력
    25
    
  2. 예제 2

    입력
    4 1 6
    4 1 2 3
    2
    
    예상 출력
    29