#P9342. [JOISC 2023 Day4] Bitaro's Travel
[JOISC 2023 Day4] Bitaro's Travel
题目描述
There is a very long road in JOI City, which can be considered as the real number line. A position on the road is represented by a real number coordinate. In JOI City, there are sightseeing spots along the road, numbered from to in ascending order of the coordinates. The coordinate of the -th sightseeing spot is .
Bitaro will visit all the sightseeing spots in JOI City. Since "greedy" is the slogan of his life, he will repeat the following procedures until he visits all the sightseeing spots.
- Let be Bitaro’s current coordinate. Among the sightseeing spots he has not yet visited, take the sightseeing spot where the distance from Bitaro's current position takes a minimum value. Then Bitaro moves to the position of the sightseeing spot , and visits it. If there are more than one such sightseeing spots, he moves to the sightseeing spot whose coordinate is smaller than the others. Here, is the absolute value of .
However, thanks to long years of experience, Bitaro knows that if he moves by repeating the above procedures, the total traveling distance may be longer than he expected. Since the total traveling distance varies according to the starting coordinate, he wants to know the total traveling distance until he visits all the sightseeing spots if he starts from each of candidates of starting coordinates .
To help Bitaro, write a program which calculates the total traveling distance if he starts from each of the candidates of starting coordinates, given information of JOI City and candidates of starting coordinates.
输入格式
Read the following data from the standard input.
输出格式
Write lines to the standard output. The -th line of output should contain the total traveling distance if Bitaro starts from the coordinate .
题目大意
题目描述
在 JOI 市里,有一条长度非常长的路,可以看做一个实数数轴。这条路上有 个景点 ,它们按照坐标递增的顺序编号。第 个景点位于坐标为 处。
Bitaro 打算参观 JOI 市的所有景点。因为贪心是他人生的口号,所以他会按以下方式不断前往最近的未参观过的景点,直到参观完毕:
令 表示 Bitaro 当前所在的位置。从尚未参观过的景点中选取距离 Bitaro 的当前位置最近的景点 ,使得 的值最小。然后将 Bitaro 移动到第 个景点并参观它。如果有多个最近的景点,则移动到它们中编号最小的那个。其中 表示 的绝对值。 但是,由于多年的经验,Bitaro 知道如果只按上述方式移动,那么他的总路程可能会比预想的更长。由于总路程和起始坐标有关,他想知道从 个起始坐标 出发,分别需要走多少路程才能参观完所有的景点。
为了帮助 Bitaro,你需要编写一个程序,给出在每个起始坐标处开始前往参观所有景点时所需走的总路程。
输出格式
共输出 行。对于每一行,输出从该起点开始走过所有景点后的总路程。
Translate by
5
0 5 6 7 9
1
7
15
10
1 2 3 4 5 6 7 8 9 10
10
1
2
3
4
5
6
7
8
9
10
9
10
11
12
13
14
15
16
17
9
提示
【样例解释 #1】
If Bitaro starts from the coordinate , he visits all the sightseeing spots as follows.
- He has not yet visited the sightseeing spots , and the distances from Bitaro’s current position are , respectively. Since the sightseeing spot is the nearest sightseeing spot from Bitaro, he stays at the coordinate and visits the sightseeing spot .
- He has not yet visited the sightseeing spots , and the distances from Bitaro’s current position are , respectively. Since the sightseeing spot is the nearest sightseeing spot from Bitaro, he moves from the coordinate to the coordinate and visits the sightseeing spot .
- He has not yet visited the sightseeing spots , and the distances from Bitaro’s current position are , respectively. Since the sightseeing spot is the nearest sightseeing spot from Bitaro, he moves from the coordinate to the coordinate and visits the sightseeing spot .
- He has not yet visited the sightseeing spots , and the distances from Bitaro’s current position are , respectively. Since the sightseeing spot is the nearest sightseeing spot from Bitaro, he moves from the coordinate to the coordinate and visits the sightseeing spot .
- He has not yet visited the sightseeing spot . Since the sightseeing spot is the nearest sightseeing spot from Bitaro, he moves from the coordinate to the coordinate and visits the sightseeing spot .
Since Bitaro’s total traveling distance is , output .
该样例满足所有子任务的限制。
【样例解释 #2】
该样例满足子任务 的限制。
【数据范围】
对于所有测试数据,满足 ,,,,保证所有输入均为整数。
子任务编号 | 分值 | 限制 |
---|---|---|
无 |