SalesforceOA #16
Get Max Efficiency
估计中等可在线判题
Assign every server exactly once to batches of the given sizes; the efficiency of a batch is its maximum capacity − its minimum capacity, and a single-element batch has efficiency 0. Find the maximum total efficiency. This definition and the rule that each element is used exactly once were recovered from the original HTML.
输入格式
The first line contains n k, the second line contains n capacity values, and the third line contains k numServers values. 1≤n≤200000, 1≤k≤n, capacities are in 1..10⁹, and every group size is ≥1, with the sizes summing to n.
输出格式
Output the maximum total efficiency, using a 64-bit integer.
样例 1
输入:
4 2
3 6 1 2
1 3
输出:
5
样例 2
输入:
4 1
1 2 3 4
4
输出:
3
样例 3
输入:
3 3
4 2 1
1 1 1
输出:
0
样例说明
The answers are 5, 3, and 0.