#P6047. 丝之割
丝之割
Background
Pharloom is a mysterious kingdom, where Silksong is the strongest power. A multi-string harp is a powerful weapon in Pharloom, just like polynomials are powerful weapons in OI.
Because you hate polynomials, you decide to destroy the multi-string harp.
Problem Description
The following part is only to help you understand the idea, and does not explain everything in detail. A more rigorous and clear statement is given in the formal statement.
A multi-string harp consists of two pillars and strings connecting the two pillars. On each pillar, there are evenly placed fixed points. The -th string connects the -th fixed point on the upper pillar and the -th fixed point on the lower pillar.

The picture above shows a multi-string harp.
To destroy the multi-string harp, you can perform several cutting operations. In one cutting operation, you may choose a fixed point on the upper pillar and a fixed point on the lower pillar. All strings that are crossed from left to right by the line segment from to will be destroyed. At the same time, you need to pay a cost of .
Formal statement: There are strings. A string can be abstracted as an ordered pair . You may perform any number of cutting operations. In one cutting operation, you choose two indices and such that , and then all strings satisfying will be destroyed, while you pay a cost of . Find the minimum total cost to destroy all strings.
Input Format
The first line contains two integers .
The second line contains integers .
The third line contains integers .
The next lines each contain two integers , indicating a string .
The meaning of the input is as described in the statement.
Output Format
Output one integer in one line, the answer.
5 2
3 9 1 9 9
9 9 1 9 3
2 1
5 4
6
5 1
9 9 9 9 1
1 9 9 9 9
3 3
81
Hint
Sample Explanation
For the first sample, use two cuts, namely and , with total cost .
For the second sample, note that cutting cannot make the string disappear.
Constraints
This problem uses bundled testdata.
For all test points, it is guaranteed that , , , and .
.
.
.
.
.
No additional constraints.
Hint
If you look carefully at the constraints, you will find that this multi-string harp can always be destroyed.
Translated by ChatGPT 5