#7613. [MCO 2023] Two Pointers (hard version)
[MCO 2023] Two Pointers (hard version)
[MCO 2023] Two Pointers (hard version)
题目描述
Alice and Bob are driving on a very long road that stretches from points $-10^9$ to $10^9$. Alice starts at point $A$ while Bob starts at point $B$. There are $n$ events to visit, where event $i$ is at position $t_i$. Either Alice or Bob must visit each event, but they must be visited $\textbf{in order}$ (they must visit event $1$, then event $2$, then event $3$, $\dots$ then event $n$).Find the minimum distance Alice and Bob can drive to visit all events.
输入格式
The first line contains a single integer $n$ ($1\le n\le3\cdot10^5$) --- 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 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
提示
### NoteIn 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 标签: P15292|2023|MCC/MCO(马来西亚)