#P3173. [HAOI2009] 巧克力
[HAOI2009] 巧克力
Description
There is a rectangular chocolate bar of size , to be cut into pieces. There are horizontal lines and vertical lines on the bar. Each time, you may cut along one of these horizontal or vertical lines. Regardless of the cut length, the costs of cutting along the horizontal lines in order are , and along the vertical lines in order are .
For the chocolate shown below, suppose we first cut along the three horizontal lines, requiring cuts, producing chocolate strips. Then we cut these strips along the vertical lines, each requiring cuts. The total cost is .

Of course, the simple method above is not necessarily optimal. How should we cut this chocolate bar to minimize the total cost?
Input Format
The first line contains two integers and .
The next lines each contain one integer, representing .
The next lines each contain one integer, representing .
Output Format
Output a single integer, the minimum cost to cut the chocolate.
6 4
2
1
3
1
4
4
1
2
42
Hint
For of the testdata, .
For of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号