#P6122. [NEERC 2016] Mole Tunnels
[NEERC 2016] Mole Tunnels
Description
The moles have dug burrows underground, connected by tunnels. For any , there is a tunnel between burrow and burrow . Burrow contains units of food, which can feed at most moles. There are moles in total, and the -th mole lives in burrow .
One morning, the first moles wake up, while the remaining moles are asleep. The first moles start looking for food. In the end, each of them will arrive at some burrow, such that for every burrow, is greater than or equal to the number of awake moles in that burrow. The total length of all moles’ movement paths must be minimized. For all , output the minimum possible total length of the moles’ movement paths. It is guaranteed that there is always a feasible solution.
Input Format
The first line contains two integers , meaning there are burrows and moles.
The second line contains integers , representing the amount of food in burrow .
The third line contains integers , where is the burrow where the -th mole is located.
Output Format
Output one line with integers. The -th integer denotes the minimum total length of the moles’ movement paths when .
5 4
0 0 4 1 1
2 4 5 2
1 1 2 4
Hint
For all testdata: , , .
Translated by ChatGPT 5
京公网安备 11011102002149号