P26290 [AtCoder] Number Line
提高
题目描述

Problem Description

There are $ N $ points on a number line. The coordinate of the $ i $ -th $(1 \leq i \leq N)$ point is $ x_i $.

The distance between coordinates $ p $ and $ q $ is $ |p-q| $.

You are given $ Q $ queries. In the $ i $ -th $(1 \leq i \leq Q)$ query, a coordinate $ t_i $ on the number line is given. Calculate the sum of the distances from this point to the $ N $ points.

Input Format

The input is given in the following format:

$ N $ $ Q $ $ x_1 $ ... $ x_N $ $ t_1 $ : $ t_Q $

Output Format

Output the answer for the $ i $ -th query on the $ i $ -th line $(1 \leq i \leq Q)$.

Sample Input and Output

Sample Input #1

5 4
1 4 5 8 10
3
4
7
11

Sample Output #1

17
14
15
27

Sample Input #2

8 10
-499 -120 32 255 571 890 1011 1256
0
-200
2500
364
-117
50
-612
889
32
364

Sample Output #2

4634
5594
16604
4060
5102
4470
8292
4696
4506
4060

Notes/Hints

Constraints

  • $1 \leq N \leq 100,000$
  • $1 \leq Q \leq 100,000$
  • $-10^9 \leq x_i \leq 10^9$ $(1 \leq i \leq N)$
  • $-10^9 \leq t_i \leq 10^9$ $(1 \leq i \leq Q)$
  • $ x_i < x_{i+1} $ $(1 \leq i \leq N-1)$

Sample Explanation 1

For example, in the $ 1 $ -th query, $ t_1=3 $ is given. The sum of the distances from this coordinate to the $ N $ points is $ |1-3| + |4-3| + |5-3| + |8-3| + |10-3| = 17 $.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
5 4 1 4 5 8 10 3 4 7 11
样例输出
17 14 15 27