logo AlgoBeat OnlineJudge
登录 注册

#215442. [MCO 2023] Two Pointers (hard version)

内存限制:256 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

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.

输入格式

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 an integer --- the minimum total distance Alice and Bob drive.

样例

样例输入 1

5
2 3
5 1 4 4 7

样例输出 1

7

样例输入 2

6
540 152
450 600 532 496 325 336

样例输出 2

526

样例输入 3

8
35 315
-406 -543 114 205 -840 161 540 -731

样例输出 3

1699

数据范围与提示

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