#P1987. 摇钱树
摇钱树
Description
Cpg is visiting a city of dreams that has money trees. Each tree has already ripened. Cpg can stay in the city for 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 . Let the -th tree initially have coins, and let it lose coins per day. If the -th tree is cut on day , the coins Cpg obtains from it are . A tree, once cut, is no longer available on later days. Cpg may cut at most one tree per day, for up to days (or until all trees are cut).
Please help Cpg compute the maximum total number of coins he can obtain over these days.
Input Format
This problem contains multiple test cases within a single input file. There are at most test cases.
Each test case:
- The first line contains two integers .
- The second line contains integers , the number of coins on each tree when Cpg first sees them.
- The third line contains integers , 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 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 of the testdata, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号