#P10041. [CCPC 2023 北京市赛] 史莱姆工厂

[CCPC 2023 北京市赛] 史莱姆工厂

Problem Description

There are nn slimes in a line. The color of the ii-th slime is cic_i, and its mass is mim_i.

You may perform the operation of increasing the mass of one slime by 11 any number of times, which costs ww each time.

However, once a slime’s mass reaches kk or above, it becomes unstable and must be sold before the next operation. You can only sell slimes whose mass is greater than or equal to kk. According to the market price, selling a slime of mass ii yields an income of pip_i. It is guaranteed that pipi1<wp_i - p_{i-1} < w. However, pip_i is not guaranteed to be non-decreasing.

After selling a slime, the slimes on its two sides will be squeezed together and become adjacent. If these two slimes have the same color, they will merge into one slime whose mass is the sum of their masses. This new slime may also need to be sold, and the process may continue.

You want to know the maximum net profit you can earn by selling all slimes.

Input Format

The first line contains three positive integers $n, k, w \ (1 \le n \le 150, 2 \le k \le 10, 1 \le w \le 10^6)$.

The second line contains nn positive integers. The ii-th integer is ci (1cin)c_i \ (1 \le c_i \le n). It is guaranteed that cici1c_i \not= c_{i-1}.

The third line contains nn positive integers. The ii-th integer is mi (1mi<k)m_i \ (1 \le m_i < k).

The fourth line contains k1k - 1 integers, which represent the income for selling slimes of mass kk to 2k22k - 2, i.e. pkp_k to p2k2p_{2k-2}. It is guaranteed that 0pi1090 \le p_i \le 10^9, and pipi1<wp_i - p_{i-1} < w.

It is guaranteed that the colors of any two adjacent slimes are different.

Output Format

Output one integer in one line, representing the maximum net profit from selling all slimes.

4 5 6
2 1 2 3
3 3 3 4
5 7 9 11
-1

Hint

First, increase the mass of the slime with color 33. Then it is sold, yielding an income of 55.

Then increase the mass of the slime with color 11 twice. Then it is sold, yielding an income of 55. Next, the two slimes with color 22 merge and are sold, yielding an income of 77.

Three operations cost 1818, so the net profit is 1-1. It can be proven that there is no better plan.

Translated by ChatGPT 5