Logo
(追記) (追記ここまで)

28003번 - Bitaro’s Travel 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB101454143.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.

  • Let $x$ be Bitaro’s current coordinate. Among the sightseeing spots he has not yet visited, take the sightseeing spot $i$ where the distance $|x − X_i|$ from Bitaro’s current position takes a minimum value. Then Bitaro moves to the position of the sightseeing spot i, 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, $|t|$ is the absolute value of $t$.

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ドル ≤ N ≤ 200,000円$.
  • 1ドル ≤ Q ≤ 200,000円$.
  • 0ドル ≤ X_i ≤ 10^9$ (1ドル ≤ i ≤ N$).
  • $X_i < X_{i+1}$ (1ドル ≤ i ≤ N - 1$).
  • 0ドル ≤ S_j ≤ 10^9$ (1ドル ≤ j ≤ Q$).
  • Given values are all integers.

서브태스크

번호배점제한
15

$Q = 1,ドル $N ≤ 2,000円$.

210

$Q = 1$.

330

$X_{i+1} − X_i ≤ 100$ (1ドル ≤ i ≤ N - 1$).

455

No additional constraints.

예제 입력 1

5
0 5 6 7 9
1
7

예제 출력 1

15

If Bitaro starts from the coordinate 7ドル,ドル he visits all the sightseeing spots as follows.

  1. He has not yet visited the sightseeing spots 1,ドル 2, 3, 4, 5,ドル and the distances from Bitaro’s current position are 7,ドル 2, 1, 0, 2,ドル respectively. Since the sightseeing spot 4ドル$ is the nearest sightseeing spot from Bitaro, he stays at the coordinate 7ドル$ and visits the sightseeing spot 4ドル$.
  2. He has not yet visited the sightseeing spots 1,ドル 2, 3, 5,ドル and the distances from Bitaro’s current position are 7,ドル 2, 1, 2,ドル respectively. Since the sightseeing spot 3ドル$ is the nearest sightseeing spot from Bitaro, he moves from the coordinate 7ドル$ to the coordinate 6ドル$ and visits the sightseeing spot 3ドル$.
  3. He has not yet visited the sightseeing spots 1,ドル 2, 5,ドル and the distances from Bitaro’s current position are 6,ドル 1, 3,ドル respectively. Since the sightseeing spot 2ドル$ is the nearest sightseeing spot from Bitaro, he moves from the coordinate 6ドル$ to the coordinate 5ドル$ and visits the sightseeing spot 2ドル$.
  4. He has not yet visited the sightseeing spots 1,ドル 5,ドル and the distances from Bitaro’s current position are 5,ドル 4,ドル respectively. Since the sightseeing spot 5ドル$ is the nearest sightseeing spot from Bitaro, he moves from the coordinate 5ドル$ to the coordinate 9ドル$ and visits the sightseeing spot 5ドル$.
  5. He has not yet visited the sightseeing spot 1ドル$. Since the sightseeing spot 1ドル$ is the nearest sightseeing spot from Bitaro, he moves from the coordinate 9ドル$ to the coordinate 0ドル$ and visits the sightseeing spot 1ドル$.

Since Bitaro’s total traveling distance is 15ドル,ドル output 15ドル$.

This sample input satisfies the constraints of all the subtasks.

예제 입력 2

10
1 2 3 4 5 6 7 8 9 10
10
1
2
3
4
5
6
7
8
9
10

예제 출력 2

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번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /