Reorder
시간 제한2.5초메모리 제한1024 MB
N개의 수로 이루어진 배열이 주어질 때, 각 R에 대해 인접한 원소를 교환하는 비용의 합과 앞 R개 원소 합의 A배를 더한 값이 최소가 되도록 만드는 문제를 Q개의 질의에 대해 해결한다.
문제
You are given numbers – , and an integer . You can do an unlimited number of swaps in the array by swapping and for a cost of . The new array after the swap would then be . For a certain number , your task it to find the minimum sum of the costs of your swaps and . Given queries and an for each of them, find the minimum cost you can achieve for each query. All queries are independent.
입력
There are integers on the first line: – the size of the array, – the number of queries and – the coefficient is multiplied by. The second line of the input contains positive integers - the starting array. The last line holds the positive integers .
출력
On each of the lines output the minimum cost for the corresponding query.
제한
힌트
Example №1: It is optimal to not swap any elements. The cost is then .
Example №2: We can first swap with and then with :
The costs of the swaps are and . Therefore, the total cost is
.