| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 | 1024 MB | 101 | 45 | 41 | 43.158% |
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 $N$ sightseeing spots along the road, numbered from 1ドル$ to $N$ in ascending order of the coordinates. The coordinate of the $i$-th sightseeing spot (1ドル ≤ i ≤ N$) is $X_i$.
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.
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 $Q$ candidates of starting coordinates $S_1, S_2, \dots , S_Q$.
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.
$N$
$X_1$ $X_2$ $\cdots$ $X_N$
$Q$
$S_1$
$S_2$
$\vdots$
$S_Q$
Write $Q$ lines to the standard output. The $j$-th line (1ドル ≤ j ≤ Q$) of output should contain the total traveling distance if Bitaro starts from the coordinate $S_j$.
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 5 | $Q = 1,ドル $N ≤ 2,000円$. |
| 2 | 10 | $Q = 1$. |
| 3 | 30 | $X_{i+1} − X_i ≤ 100$ (1ドル ≤ i ≤ N - 1$). |
| 4 | 55 | No additional constraints. |
5 0 5 6 7 9 1 7
15
If Bitaro starts from the coordinate 7ドル,ドル he visits all the sightseeing spots as follows.
Since Bitaro’s total traveling distance is 15ドル,ドル output 15ドル$.
This sample input satisfies the constraints of all the subtasks.
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
This sample input satisfies the constraints of Subtasks 3, 4.
Camp > JOI Spring Training Camp > JOI 2022/2023 Spring Training Camp 4-3번
Camp > JOIG Spring Training Camp > JOIG 2022/2023 Spring Training Camp 4-3번