#P6515. [QkOI#R1] Quark and Game
[QkOI#R1] Quark and Game
Description
Given pairs . When , this pair can no longer be operated on. You can perform two operations:
-
For all operable pairs, do , i.e., decrease by , with cost .
-
For all operable pairs, do , where means swapping the values of and , with cost .
Now, you need to spend the minimum total cost to make all pairs non-operable.
Input Format
The first line contains three positive integers .
The next lines each contain two positive integers , representing the -th pair .
Output Format
Output one integer in one line, representing the minimum total cost.
4 9 5
1 7
1 4
6 5
4 2
23
3 500 3
4 6
3 5
8 1
1000
2 1 1000
1 500
2 800
500
Hint
Sample Explanation
For the first sample, we can perform operation 1 once, operation 2 once, and operation 1 once in this order. The minimum cost is .
For the second sample, we can perform operation 1 twice. The minimum cost is .
For the third sample, we can perform operation 1 times. The minimum cost is .
Constraints
This problem uses bundled testdata.
- Subtask 1 (10 pts): , .
- Subtask 2 (20 pts): , .
- Subtask 3 (17 pts): , .
- Subtask 4 (53 pts): no special constraints.
For of the testdata, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号