No.2549 Paint Eggs
タグ : / 解いたユーザー数 65
作問者 :
sepa38
Seed57_cash
Problem Statement
$N$ eggs are lined up in a row.
Each egg is painted in one of the colors represented by integers from $1$ to $M$, and the $i \: (1 \leq i \leq N)$-th egg from the left is painted in color $C_i$.
You may choose any egg and repaint it any number of times, and repainting an egg to color $j \: (1 \leq j \leq M)$ costs $A_j$.
Find the minimum cost required to make the colors of some $K$ consecutive eggs all the same.
Constraints
- $1 \leq K \leq N \leq 2 \times 10^{5}$
- $1 \leq M \leq 2 \times 10^{5}$
- $1 \leq C_i \leq M$
- $1 \leq A_j \leq 10^{9}$
- All input values are integers.
Input
The input is given from standard input in the following format.
$N$ $M$ $K$ $C_1$ $C_2$ ... $C_N$ $A_1$ $A_2$ ... $A_M$
Output
Output the answer to the problem on one line.
Sample
Sample 1
Input
5 3 3 1 2 1 3 2 10 10 10
Output
10
If you repaint the $2$-nd egg to color $1$, the $1$-st through $3$-rd eggs will have the same color, which achieves the goal.
The cost is $10$, and it cannot be made any smaller.
Sample 2
Input
5 3 3 1 1 1 1 1 10 10 10
Output
0
The goal may already be achieved from the start.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。