Codeforces Round 1051 (Div. 2)
B
Discounts
Codeforces
1000
原题
← AC →
翻译中…

You want to buy $n$ products with prices $a_1, a_2, \ldots, a_n$. You can either:

翻译中…
  • buy product $i$ individually, paying $a_i$ coins, or
  • use a discount voucher to buy it as part of a group purchase.
翻译中…

You have $k$ discount vouchers with values $b_1, b_2, \ldots, b_k$. A voucher of value $x$ allows you to select exactly $x$ products and pay only for the $x - 1$ most expensive ones, as such, you can consider that the cheapest product in the group is free. Each product can be included in at most one discount group, even if it is not the free one. Also, any single voucher can be used at most one single time.

翻译中…

What is the minimum total cost required to purchase all $n$ products?

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The first line contains two integers $n$ and $k$ ($1 \le n, k \le 2 \cdot 10^5$) —the number of products and the number of available discount vouchers.

翻译中…

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$) — the prices of the products.

翻译中…

The third line contains $k$ integers $b_1, b_2, \ldots, b_k$ ($1 \le b_i \le n$) — the values of the discount vouchers.

翻译中…

It is guaranteed that the sum of $n$ across all test cases does not exceed $2 \cdot 10^5$, and the sum of $k$ across all test cases does not exceed $2 \cdot 10^5$.

翻译中…

Output

翻译中…

Print $t$ lines. The $i$-th line should contain the answer for the $i$-th test case — the minimum total cost required to purchase all products in that test case.

翻译中…

Note

翻译中…

In the first test case, you can apply the first discount to products 2, 3, and 4. You will pay for the two most expensive ones (3 and 7 coins) and get the cheapest one for free, resulting in a cost of $3 + 7 = 10$ coins. Then, apply the second and third discounts to products 1 and 5, getting both for free. The total cost is $10$ coins.

翻译中…

In the second test case, you can use the single discount on products 2, 3, 4, 5, and 6. Among them, the cheapest is product 2 (costing 2 coins), which you get for free. You pay for the remaining products: $1 + 6 + 3 + 3 + 4 = 17$ coins in total.

翻译中…

In the third test case, only one discount is available. You can use it on both products, getting the cheaper one for free and paying $1$ coin for the other.

翻译中…

样例

Input #1
5
5 3
18 3 7 2 9
3 1 1
6 1
1 2 6 3 3 4
5
2 3
1 1
2 2 2
1 1
10
1
5 3
99 99 999 999 123
2 1 4
Output #1
10
17
1
0
1197
InputCopy OutputCopy
题目信息
题号
2143B
时间限制
1 s
内存限制
256 MB
标签
贪心
排序
双指针

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。