#P6235. [eJOI 2019] 矩形染色
[eJOI 2019] 矩形染色
Background
Warning: Abusing the judging system for this problem will result in your account being banned.
Problem Description
Srečko wants to color every cell in a rectangular grid with rows (indexed from to ) and columns (indexed from to ). At the beginning, the whole rectangle is white. In each step, he chooses one diagonal and colors all cells on that diagonal. Coloring a diagonal costs a certain amount (ignore its length), so some diagonals may cost more to color than others.
You need to write a program that reads the coloring cost of each diagonal and outputs the minimum total cost to color all cells.
Note that recoloring the same cell multiple times is allowed.
An rectangular grid has a total of diagonals.
Example: when , there are diagonals in total:

Input Format
The input has lines.
The first line: two integers .
The second line: integers describing all diagonals in the direction. The st integer corresponds to the single cell , the nd integer corresponds to the two cells , and so on.
The third line: integers describing all diagonals in the direction. The st integer corresponds to the single cell , the nd integer corresponds to the two cells , and so on.
Output Format
Output one integer, the answer.
2 2
1 3 1
1 3 1
4
4 3
2 3 9 3 4 3
2 3 3 1 2 4
14
Hint
Sample Explanation
Sample 1 Explanation
- In this case, the following plan can achieve the minimum cost:

Total cost .
Sample 2 Explanation
- In this case, the following plan can minimize the total cost:

Total cost .
Constraints
This problem uses bundled subtasks, with subtasks in total.
- Subtask 1 (10 points):
- Subtask 2 (10 points):
- Subtask 3 (10 points):
- Subtask 4 (20 points):
- Subtask 5 (10 points):
- Subtask 6 (20 points):
- Subtask 7 (20 points): no other constraints.
For all testdata, it is guaranteed that , and the coloring cost of each diagonal is .
Notes
The original problem is from: eJOI2019 Problem E. Colouring a rectangle.
Translation provided by: @_Wallace_。
Translated by ChatGPT 5