| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 | 1024 MB | 44 | 14 | 14 | 33.333% |
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 in order (they must visit event $1$, then event $2$, then event $3$, \dots then event $n$).
Find the minimum total 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 $A$ and $B$ ($-10^9\le A,B\le10^9$) --- Alice and Bob's starting points.
The third line contains $n$ integers $t_1,t_2,\dots,t_n$ ($-10^9\le t_i\le10^9$) --- the locations of events either Alice or Bob must get to.
Output an integer --- the minimum total distance Alice and Bob drive.
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 5 | $|t_i|,|A|\le1000,B=10^9$ |
| 2 | 8 | $n\le20$ |
| 3 | 19 | $n\le3000$ |
| 4 | 12 | $n\le10^5,|t_i|,|A|,|B|\le100$ |
| 5 | 43 | $|t_i|,|A|,|B|\le2\cdot10^5$ |
| 6 | 13 | No additional constraints |
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
In the first example:
The total distance travelled is $2+1+1+0+3=7$.
In the second example, Alice visits all events.