#P17302. [ICPC 2026 Xi'an I] VIP Coupon
[ICPC 2026 Xi'an I] VIP Coupon
题目描述
Yuki has many fond memories of Chang'an, so she visited a shop intending to buy some souvenirs to take home.
The shop sells souvenirs and VIP coupons. The price of the -th souvenir is , and the -th VIP coupon has a price and a parameter . The effect of a VIP coupon with parameter is as follows:
- If the price of the item (including souvenirs and other VIP coupons) purchased immediately after buying this coupon is , the price of that item becomes .
The effect of a VIP coupon is mandatory for the very next purchase and cannot be deferred. Clearly, based on this rule, the effects of VIP coupons cannot be stacked. Each item (including souvenirs and VIP coupons) can be purchased ; they cannot be bought repeatedly.
Yuki intends to purchase all souvenirs and any number of VIP coupons (possibly zero) in any order. You need to help Yuki find the minimum cost to purchase all the souvenirs.
输入格式
The input contains multiple test cases.
The first line contains a positive integer , representing the number of test cases.
For each test case:
- The first line contains two positive integers .
- The second line contains integers .
- The third line contains integers .
- The fourth line contains integers .
It is guaranteed that the sum of and over all test cases does not exceed .
输出格式
For each test case, output a single integer representing the minimum cost to purchase all souvenirs.
2
2 4
4 7
1 3 2 4
5 2 6 5
3 3
2 3 8
0 5 2
4 7 5
4
5
提示
For the first test case:
- Yuki can purchase the coupons and souvenirs in the following order: 1st coupon, 1st souvenir, 3rd coupon, 2nd souvenir.
- After the discounts, the price of the 1st souvenir becomes , and the price of the 2nd souvenir becomes . The total cost is .
For the second test case:
- Yuki can purchase the items in the following order: 1st souvenir, 1st coupon, 2nd souvenir, 3rd coupon, 2nd coupon, 3rd souvenir.
- After the discounts, the price of the 2nd souvenir becomes , the price of the 2nd coupon becomes , and the price of the 3rd souvenir becomes . The total cost is .