#P3992. Minimum Total Fuel Cost
Minimum Total Fuel Cost
Minimum Total Fuel Cost
There are (n) cars located at positions (a_1, a_2, \ldots, a_n) and (n) gas stations located at positions (b_1, b_2, \ldots, b_n). Each gas station can refuel at most one car. A car moving from position (x) to (y) incurs a cost of (|x-y|). The goal is to assign each car to a distinct gas station such that the total cost is minimized.
In addition, you are given (q) operations. In each operation, the position of the (i)-th car is updated to (x). After each update, you must output the minimized total cost under the new configuration.
inputFormat
The first line contains two integers (n) and (q).
The second line contains (n) integers (a_1, a_2, \ldots, a_n), representing the initial positions of the cars.
The third line contains (n) integers (b_1, b_2, \ldots, b_n), representing the positions of the gas stations.
Each of the next (q) lines contains two integers (i) and (x), indicating that the (i)-th car's position is updated to (x).
outputFormat
For each of the (q) operations, output a single line with the minimized total cost after the car's position has been updated.
sample
3 2
4 1 5
2 3 6
2 4
1 3
4
3
</p>