CF2143B.Discounts

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

Discounts

You want to buy nn products with prices a1,a2,,ana_1, a_2, \ldots, a_n. You can either:

  • buy product ii individually, paying aia_i coins, or
  • use a discount voucher to buy it as part of a group purchase.

You have kk discount vouchers with values b1,b2,,bkb_1, b_2, \ldots, b_k. A voucher of value xx allows you to select exactly xx products and pay only for the x1x - 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 nn products?

Input

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

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

The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (1ai1091 \le a_i \le 10^9) — the prices of the products.

The third line contains kk integers b1,b2,,bkb_1, b_2, \ldots, b_k (1bin1 \le b_i \le n) — the values of the discount vouchers.

It is guaranteed that the sum of nn across all test cases does not exceed 21052 \cdot 10^5, and the sum of kk across all test cases does not exceed 21052 \cdot 10^5.

Output

Print tt lines. The ii-th line should contain the answer for the ii-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=103 + 7 = 10 coins. Then, apply the second and third discounts to products 1 and 5, getting both for free. The total cost is 1010 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=171 + 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 11 coin for the other.

Samples

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
10
17
1
0
1197

在线编程 IDE

建议全屏模式获得最佳体验