#P10712. [NOISG 2024 Prelim] Explosives
[NOISG 2024 Prelim] Explosives
Background
Translated from NOI SG 2024 Prelim E.Explosives。
Problem Description
You are a truck driver transporting bombs.
There are factories (producing bombs) and mines (needing bombs) arranged on a straight line. The coordinate of the -th factory is , and the coordinate of the -th mine is . Also, all and are pairwise distinct.
Today, you need to pick up one bomb from each factory, and deliver each bomb to some mine. Initially, your position is . To complete this task, you may perform the following two operations:
-
pickup(x): Drive the truck from your current position to the factory located at . To perform this operation, the following two conditions must both hold:- There exists an such that 。
- Your truck currently carries at most bombs.
-
offload(x): Drive the truck from your current position to the mine located at . To perform this operation, the following two conditions must both hold:- There exists a such that 。
- Your truck currently carries at least bomb.
Because bombs are very dangerous, a safety officer must be on your truck. If you travel from point to point while the truck is carrying bombs, then you need to pay the safety officer dollars. If the truck is carrying no bombs, then you do not need to pay any cost.
Find an operation sequence with the minimum total cost.
Input Format
The first line contains two integers 。
The second line contains integers, representing 。
The third line contains integers, representing 。
Output Format
The first line contains one integer, the minimum cost.
The second line outputs integers, representing the coordinates of the factories and mines you visit, in the order you visit them.
For example, if you perform four operations: pickup(3), offload(5), pickup(6), offload(2), then you should output 3 5 6 2。
3 2
12 14 4
9 5 8
7
4 5 14 12 9 8
Hint
Sample #1 Explanation
Visit factory , mine , factory , factory , mine , mine in this order, and you can obtain the minimum value 。
In this sample, if you only output the correct minimum cost , you can get of the score for this testdata point.
Constraints
| Score | Special Property | |
|---|---|---|
| Sample | ||
| None | ||
For of the data, 。
Translated by ChatGPT 5