#P9342. Sightseeing Greedy Tour

    ID: 22495 Type: Default 1000ms 256MiB

Sightseeing Greedy Tour

Sightseeing Greedy Tour

Bitaro is visiting all the sightseeing spots in JOI City, which lie on a real number line. The city has N sightseeing spots located at coordinates \(X_1, X_2, \dots, X_N\) with \(X_1 < X_2 < \dots < X_N\). Starting from a given coordinate \(S\), he will repeatedly move to the nearest unvisited spot. In case two or more spots are equally near, he chooses the one with the smallest coordinate. The distance between two points \(a\) and \(b\) is defined as \(|a-b|\), where \(|\cdot|\) denotes the absolute value.

Your task is to compute the total traveling distance Bitaro covers until all the sightseeing spots have been visited for each candidate starting coordinate.

inputFormat

The input is given in the following format:

N Q
X1 X2 ... XN
S1
S2
. . .
SQ

Where:

  • The first line contains two integers \(N\) and \(Q\), the number of sightseeing spots and the number of starting coordinate queries.
  • The second line contains \(N\) space-separated real numbers \(X_1, X_2, \dots, X_N\) sorted in ascending order.
  • Each of the next \(Q\) lines contains a real number \(S_i\), a candidate starting coordinate.

outputFormat

For each query, output the total traveling distance Bitaro covers as he visits all the sightseeing spots, each on a new line.

sample

5 3
1 5 9 10 12
7
6
12
17

16 11

</p>