#C. 冲击高考win

    Type: Default File IO: win 1000ms 512MiB

冲击高考win

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

题目描述

李尚道 和 张恒瑞 两个人一起备战高考,他们需要一起解决所有难题。可以看做他们在一条长长的河中游泳,这条河叫题河。

题河可以看成一条数轴,左端点坐标109-10^9,右端点坐标 10910^9

开始时,李尚道在点A,张恒瑞在点B。他们需要合作KO所有题目。

题河中有 nn 个题目,每个题目看成一个点,第 ii 个要做的题目坐标为 tit_i

AABB 耗时 |A-B|。

每道题目至少要被其中某一个人做一次。需要依次完成每一题。先做第一题,再做第二题,...。

问两人游泳的总距离(耗时)最少是多少。

输入格式

第一行一个整数 nn。 第二行两个整数 A,BA, B, 第三行 nn 个整数 t1,t2,...,tnt_1,t_2,...,t_n

输出格式

一个整数。

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

样例解释1

李尚道从2--->1(题目2),张恒瑞3-->5(题目1)--->4(题目3)--->4(题目4)--->7(题目5)。

李尚道花费时间1,张恒瑞花费时间2+1+0+3=6,总时间为7.

数据范围

对于所有数据 1n3105,109A,B,ti1091\le n \le 3*10^5, -10^9 \le A,B,t_i \le 10^9

子任务1(5分):ti,A1000;B=109|t_i|,|A|\le 1000; B=10^9

子任务2(8分):n20n\le 20

子任务3(19分):n3000n\le 3000

子任务4(12分):n105;ti,A,B100n\le 10^5; |t_i|,|A|,|B|\le 100$

子任务5(43分):ti,A,B2105|t_i|,|A|,|B|\le 2*10^5

子任务6(13分)

CSP-S模拟赛

Not Attended
Status
Done
Rule
OI
Problem
4
Start at
2023-10-17 8:00
End at
2023-10-17 12:00
Duration
4 hour(s)
Host
Partic.
25