QOJ.ac

QOJ

时间限制: 1 s 内存限制: 512 MB 总分: 100

#7988. Slime Factory

统计

There are $n$ slimes arranged in a row, where the $i$-th slime has color $c_i$ and mass $m_i$.

You can perform an operation to increase the mass of a slime by $1$ at a cost of $w$.

However, once a slime's mass reaches $k$ or more, it becomes unstable and must be sold before any further operations can be performed. You can only sell slimes with a mass of at least $k$. According to the market price, selling a slime of mass $i$ yields a profit of $p_i$. It is guaranteed that $p_i - p_{i-1} < w$. Note that $p_i$ is not guaranteed to be monotonically non-decreasing.

After a slime is sold, the slimes on either side of it are pushed together. If these two slimes have the same color, they will merge into a single slime with a mass equal to the sum of their masses. This new slime may also need to be sold, potentially triggering the process again.

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

Input

The input is read from standard input.

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 $n$ positive integers, where the $i$-th integer represents $c_i$ ($1 \le c_i \le n$). It is guaranteed that $c_i \neq c_{i-1}$.

The third line contains $n$ positive integers, where the $i$-th integer represents $m_i$ ($1 \le m_i < k$).

The fourth line contains $k-1$ integers representing the revenue from selling slimes with masses from $k$ to $2k-2$, i.e., $p_k$ to $p_{2k-2}$. It is guaranteed that $0 \le p_i \le 10^9$ and $p_i - p_{i-1} < w$.

It is guaranteed that adjacent slimes have different colors.

Output

Output to standard output.

A single integer representing the maximum net profit from selling all slimes.

Examples

Input 1

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

Output 1

-1

Note 1

First, increase the mass of the slime with color $3$. Then it is sold, yielding a revenue of $5$.

Next, increase the mass of the slime with color $1$ twice. Then it is sold, yielding a revenue of $5$. Subsequently, the two slimes with color $2$ merge and are sold, yielding a revenue of $7$.

Three operations were performed at a cost of $18$, resulting in a net profit of $-1$. It can be proven that no better strategy exists.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.