#P3992. [BJOI2017] 开车
[BJOI2017] 开车
Description
There are cars located at positions , and gas stations located at positions .
Each gas station can serve at most one car, so you must drive the cars to distinct gas stations. The cost for a car to drive from position to position is . Find an assignment that minimizes the sum of costs.
You are also given operations. In each operation, the position of the -th car is updated to . After each update, you need to output the minimal total cost of an optimal assignment.
Input Format
The first line contains a positive integer .
The second line contains integers .
The third line contains integers .
The fourth line contains a positive integer , the number of operations.
Each of the next lines contains two integers () and , indicating that the position of car is updated to .
All car and gas station positions are always within to .
Output Format
Output lines. The first line is the minimal total cost before any operations.
Then output lines, where the -th line is the minimal total cost after operation .
2
1 2
3 4
1
1 3
4
2
Hint
Sample explanation:
Initially, drive the first car to position and the second car to position , with a total cost of .
After the update, the first car’s position becomes , and the total cost is .
| Test points | Constraints |
|---|---|
| , | |
| , | |
| , | |
| , | |
| , | |
| , |
For of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号