AmazonOA #307
Minimum Total Packaging Effort
估计中等可在线判题
Each of the m items must be packed exactly once. Each center can be used at most once, or not at all. At center i, paying for at least packageCount[i] items gets you 2 more items for free, and the effort of each of those two free items must not exceed that of any paid item at the center. A center grants only this one set of 2 free items, and every other item must be paid for. You may pay at a center without claiming the offer, and you may also just pay without reaching the threshold. Find the minimum total paid effort for all items.
输入格式
The first line contains m n, the second line contains m packEffort values, and the third line contains n packageCount values. The original bounds are 1≤m,n≤100000, 0≤packEffort[i]≤10000. This site adds 1≤packageCount[i]≤10^9 and does not additionally require a threshold≤m.
输出格式
Output a single integer, the answer.
样例 1
输入:
4 1
10 9 8 1
1
输出:
19
样例 2
输入:
6 2
6 5 4 3 2 1
1 1
输出:
9
样例 3
输入:
3 1
0 0 0
7
输出:
0
样例说明
The answers are 19, 9 and 0. In the first example the only center must hold all four items, so only 8 and 1 can be free; you cannot pay 10, get 9 and 8 free, and leave 1 at a center that does not exist. In the second example, one center pays 6 to get 5 and 4 free, and the other pays 3 to get 2 and 1 free.