#P1987. 摇钱树

摇钱树

Description

Cpg is visiting a city of dreams that has nn money trees. Each tree has already ripened. Cpg can stay in the city for kk days. Every day, each tree loses some coins that fall off and are not collected by Cpg. Each day, Cpg may cut down exactly one tree and obtain all the coins currently on that tree.

Formally, number the days as t=0,1,,k1t = 0, 1, \dots, k - 1. Let the ii-th tree initially have mim_i coins, and let it lose bib_i coins per day. If the ii-th tree is cut on day tt, the coins Cpg obtains from it are max(mibit,0)\max(m_i - b_i \cdot t, 0). A tree, once cut, is no longer available on later days. Cpg may cut at most one tree per day, for up to kk days (or until all trees are cut).

Please help Cpg compute the maximum total number of coins he can obtain over these kk days.

Input Format

This problem contains multiple test cases within a single input file. There are at most 1010 test cases.

Each test case:

  • The first line contains two integers n,kn, k.
  • The second line contains nn integers mim_i, the number of coins on each tree when Cpg first sees them.
  • The third line contains nn integers bib_i, the number of coins each tree loses per day.

Input is terminated by a line containing 0 0.

Output Format

For each test case, output a single line with the maximum total number of coins Cpg can obtain in kk days.

3 3
10 20 30
4 5 6
4 3
20 30 40 50
2 7 6 5
0 0

47
104

Hint

Constraints

  • For 100%100\% of the testdata, 1n,k1031 \le n, k \le 10^3, 1mi1051 \le m_i \le 10^5, 1bi1031 \le b_i \le 10^3.

Translated by ChatGPT 5