Universal Cup Judging System

Universal Cup

Süre Sınırı: 1 s Bellek Sınırı: 512 MB Toplam puan: 100 Hack'lenebilir ✓
İstatistikler

Yuki 對 Chang’an 有許多美好回憶,因此她來到一家商店,打算購買一些紀念品帶回家。

商店出售 $n$ 件紀念品和 $m$ 張 VIP 優惠券。第 $i$ 件紀念品的價格為 $a_i$,第 $j$ 張 VIP 優惠券的價格為 $b_j$,參數為 $c_j$。參數為 $v$ 的 VIP 優惠券效果如下:

  • 若購買這張優惠券後緊接著購買的商品(包括紀念品和其他 VIP 優惠券)原價為 $x$,則該商品的價格變為 $\max(x-v,0)$。

VIP 優惠券的效果必須用於緊接著的下一次購買,不能延後。顯然,根據這個規則,VIP 優惠券的效果不能疊加。每件商品(包括紀念品和 VIP 優惠券)至多只能購買一次,不能重複購買。

Yuki 打算以任意順序購買所有紀念品,以及任意數量(可以為零)的 VIP 優惠券。你需要幫助 Yuki 求出購買所有紀念品的最小花費。

輸入格式

輸入包含多組測試資料。

第一行包含一個正整數 $t$($1\le t\le10^5$),表示測試資料組數。

對於每組測試資料:

  • 第一行包含兩個正整數 $n,m$($1\le n,m\le5\cdot10^5$)。

  • 第二行包含 $n$ 個整數 $a_1,\ldots,a_n$($0\le a_i\le10^9$)。

  • 第三行包含 $m$ 個整數 $b_1,\ldots,b_m$($0\le b_i\le10^9$)。

  • 第四行包含 $m$ 個整數 $c_1,\ldots,c_m$($0\le c_i\le10^9$)。

保證所有測試資料的 $n$ 和 $m$ 的總和不超過 $5\cdot10^5$。

輸出格式

對於每組測試資料,輸出一個整數,表示購買所有紀念品的最小花費。

範例

輸入格式 1

2
2 4
4 7
1 3 2 4
5 2 6 5
3 3
2 3 8
0 5 2
4 7 5

輸出格式 1

4
5

說明

對於第一組測試資料:

  • Yuki 可以依照以下順序購買優惠券和紀念品:第 1 張優惠券、第 1 件紀念品、第 3 張優惠券、第 2 件紀念品。

  • 折扣後,第 1 件紀念品的價格變為 $0$,第 2 件紀念品的價格變為 $1$。總花費為 $1+0+2+1=4$。

對於第二組測試資料:

  • Yuki 可以依照以下順序購買商品:第 1 件紀念品、第 1 張優惠券、第 2 件紀念品、第 3 張優惠券、第 2 張優惠券、第 3 件紀念品。

  • 折扣後,第 2 件紀念品的價格變為 $0$,第 2 張優惠券的價格變為 $0$,第 3 件紀念品的價格變為 $1$。總花費為 $2+0+0+2+0+1=5$。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.