Boxes and Balls
시간 제한1초메모리 제한512 MB
M개의 상자에 공을 담는데, 요청된 공이 상자에 없으면 w를 지불하고 상자 하나에서 공을 빼내야 한다. 총비용의 최솟값을 구한다.
문제
There are boxes and balls. The balls are numbered through , and the weight of the ball is . You are also given a sequence . Each is an integer satisfying .
Initially, all the boxes are empty. For each in this order, you have to perform the following operation:
- If one of the boxes contains the ball , you do nothing. There is no cost for this operation.
- Otherwise, you choose one of the boxes and put the ball into the chosen box. However, if the chosen box already contains another ball, you should take that ball out of the box. The cost for this operation is (the cost doesn't depend on the box nor the ball you take out of the box).
Compute the minimum possible total cost of operations.
입력
The first line contains three integers , and (, ).
The -th of the next lines contains an integer ().
The -th of the next lines contains an integer ().
출력
Print the minimum total cost.