#P17302. [ICPC 2026 Xi'an I] VIP Coupon

    ID: 17193 Type: RemoteJudge 1000ms 512MiB Tried: 0 Accepted: 0 Difficulty: 8 Uploaded By: Tags>贪心堆优先队列ICPC2026省赛/邀请赛西安

[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 nn souvenirs and mm VIP coupons. The price of the ii-th souvenir is aia_i, and the jj-th VIP coupon has a price bjb_j and a parameter cjc_j. The effect of a VIP coupon with parameter vv is as follows:

  • If the price of the item (including souvenirs and other VIP coupons) purchased immediately after buying this coupon is xx, the price of that item becomes max⁡(x−v,0)\max(x - v, 0).

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 at most once\textbf{at most once}; 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 tt (1≤t≤105)(1 \le t \le 10^5), representing the number of test cases.

For each test case:

  • The first line contains two positive integers n,mn, m (1≤n,m≤5⋅105)(1 \le n, m \le 5 \cdot 10^5).
  • The second line contains nn integers a1,…,ana_1, \dots, a_n (0≤ai≤109)(0 \le a_i \le 10^9).
  • The third line contains mm integers b1,…,bmb_1, \dots, b_m (0≤bi≤109)(0 \le b_i \le 10^9).
  • The fourth line contains mm integers c1,…,cmc_1, \dots, c_m (0≤ci≤109)(0 \le c_i \le 10^9).

It is guaranteed that the sum of nn and mm over all test cases does not exceed 5⋅1055 \cdot 10^5.

输出格式

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 00, and the price of the 2nd souvenir becomes 11. The total cost is 1+0+2+1=41 + 0 + 2 + 1 = 4.

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 00, the price of the 2nd coupon becomes 00, and the price of the 3rd souvenir becomes 11. The total cost is 2+0+0+2+0+1=52 + 0 + 0 + 2 + 0 + 1 = 5.