cswork / OA打开练习工作台

AmazonOA #178

Find Network Calls (Also For Amazon UK :)

估计中等可在线判题

考点(AI 标注)前缀和区间二分查找

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.

输入格式

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 q integers in query order.

样例 1

输入:

5 1
4 6 5 2 1
3

输出:

9

样例 2

输入:

3 2
3 6 6
5 6

输出:

4 3

样例 3

输入:

1 2
1
1 2

输出:

0 1

样例说明

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