cswork / OAOpen practice workspace

AmazonOA #178

Find Network Calls (Also For Amazon UK :)

Estimated MediumJudge-ready

Topics (AI-labelled)Prefix & RangesBinary Search

Each call can only increase or decrease one product's feedback count by 1. Each target starts independently from the original array; output the minimum number of calls to turn every feedback count into that target. The source's first example output conflicts with the statement; this site corrects it to 9 using the per-item absolute differences.

Input

The first line contains n q, the second line n feedback counts, and the third line q targets. 1≤n,q≤100000, values 1..1000000.

Output

Output q integers in query order.

Example 1

Input:

5 1
4 6 5 2 1
3

Output:

9

Example 2

Input:

3 2
3 6 6
5 6

Output:

4 3

Example 3

Input:

1 2
1
1 2

Output:

0 1

Example notes

The outputs of the three examples are 9; 4 3; 0 1.

Editorial

Loading solution…