Under construction

Still being built. Things may change

Humanities and Arts Exploration Week

Interview

Time limit2sMemory limit512 MB

Summary
Given N tree positions and Q query points, output for each query the sum of absolute distances to all trees.
Level

Medium4 of 10

Topics
Sorting, Prefix sum, Binary search, Math
Solved
No attempts yet

Problem

Taeyoung is spending "Humanities and Arts Exploration Week," SASA's festival. He went to Sejong Lake Park for the occasion and was struck by how beautiful the scenery was.

Sejong Lake Park stretches out in a straight line. The park has NN trees in total, and the position of the ii-th tree is PiP_i.

Taeyoung wants to capture this beautiful scenery by taking QQ panoramic photos with his camera. He wants to give each photo a score, and the score of a photo is the sum of the distances from the position where the photo was taken to each tree. The distance between two positions is defined as the absolute value of their difference.

For each photo Taeyoung took, find its score.

Input

The first line gives the number of trees NN and the number of photos Taeyoung took QQ, separated by a space.

The second line gives the positions of the trees P1,P2,⋯ ,PNP_1, P_2, \cdots, P_N.

Among the QQ lines starting from the third line, the ii-th line gives XiX_i, the position where Taeyoung took his ii-th photo.

Output

On the ii-th line, print the score of the ii-th photo Taeyoung took, one per line in order.

Constraints

  • 1≤N,Q≤1051 \leq N,Q \leq 10^5
  • 1≤Pi≤1071 \leq P_i \leq 10^7 (1≤i≤N1 \le i \le N)
  • 1≤Xi≤1071 \leq X_i \leq 10^7 (1≤i≤Q1 \le i \le Q)
  • All numbers given in the input are integers.

Examples1

  1. Example 1

    Input
    5 2
    1 3 7 9 10
    4
    12
    
    Expected output
    18
    30