#P15292. [MCO 2023] Two Pointers (hard version)
[MCO 2023] Two Pointers (hard version)
Description
Alice and Bob are driving on a very long road that stretches from points to . Alice starts at point while Bob starts at point . There are events to visit, where event is at position . Either Alice or Bob must visit each event, but they must be visited (they must visit event , then event , then event , then event ).
Find the minimum distance Alice and Bob can drive to visit all events.
Input Format
The first line contains a single integer () --- the number of events.
The second line contains two integers and () --- Alice and Bob's starting points.
The third line contains integers () --- the locations of events either Alice or Bob must get to.
Output Format
Output an integer --- the minimum total distance Alice and Bob drive.
5
2 3
5 1 4 4 7
7
6
540 152
450 600 532 496 325 336
526
8
35 315
-406 -543 114 205 -840 161 540 -731
1699
Hint
Note
In the first example:
- Bob moves from position to position to attend event , driving units.
- Alice moves from position to position to attend event , driving unit.
- Bob moves from position to position for event , driving unit.
- Bob stays at position , attending event , driving units.
- Bob moves from position to position for event , driving units.
The total distance travelled is .
In the second example, Alice visits all events.
Scoring
Subtask 1 ( points)
Subtask 2 ( points)
Subtask 3 ( points)
Subtask 4 ( points)
Subtask 5 ( points)
Subtask 6 ( points) No additional constraints
京公网安备 11011102002149号