Universal Cup Judging System

Universal Cup

実行時間制限: 1 s メモリ制限: 512 MB 満点: 100 ハック可能 ✓
統計

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.