#P5653. 基础最优化练习题

基础最优化练习题

Description

YSGH has a number xx with initial value 00. For the next nn minutes, each minute YSGH can add an integer yy to xx, where y[k,k]y \in [-k, k]. At the same time, YSGH must ensure that at the end of the ii-th minute, xaix \le a_i.

Let bib_i be the value of xx at the end of the ii-th minute. Now YSGH gives you a sequence ww of nn numbers. You need to maximize i=1nbiwi\displaystyle \sum_{i = 1}^{n} b_i w_i.

You only need to output the maximum value.

Input Format

The first line contains two positive integers n,kn, k, with the same meaning as in the statement.

The second line contains nn integers, where the ii-th integer is aia_i, with the same meaning as in the statement.

The third line contains nn integers, where the ii-th integer is wiw_i, with the same meaning as in the statement.

It is guaranteed that the input ensures there exists at least one sequence bb that satisfies the conditions.

Output Format

The first line contains one integer, which is the answer.

5 1
4 3 2 3 2
5 7 -5 9 -10
24

Hint

For 10%10\% of the data, n10n \le 10, k1k \le 1.
For 20%20\% of the data, n100n \le 100.
For 30%30\% of the data, n103n \le 10^3.
For 50%50\% of the data, n104n \le 10^4.
There is another 10%10\% of the data where wi0w_i \ge 0.
For 100%100\% of the data, 1n1061 \le n \le 10^6, 106wi106-10^6 \le w_i \le 10^6, 0ai1080 \le a_i \le 10^8, 1k1001 \le k \le 100.

Translated by ChatGPT 5