IBMOA #60
Minimum Operations Required (2025 Intern)
估计中等可在线判题
Each operation adds 1 to or subtracts 1 from one element. For each query value, find the minimum number of operations to turn all elements into that value. Queries are independent; the original array is restored before the next query.
输入格式
The first line contains n q, the second line contains the array, and the third line contains q queries. On this site 1≤n,q≤100000, and the array values and queries are integers in −10^9..10^9.
输出格式
Output q lines of integers in query order.
样例 1
输入:
4 2
3 1 6 8
1 5
输出:
14
10
样例 2
输入:
4 1
2 9 6 3
10
输出:
20
样例 3
输入:
3 3
1 1 1
1 2 1
输出:
0
3
0
样例说明
The examples give 14 and 10; 20; and 0, 3, 0 respectively.