Universal Cup Judging System

Universal Cup

Time Limit: 1 s Memory Limit: 512 MB Total points: 100 Hackable ✓
Statistics

Yuki has many fond memories of Chang’an, so she visited a shop intending to buy some souvenirs to take home.

The shop sells $n$ souvenirs and $m$ VIP coupons. The price of the $i$-th souvenir is $a_i$, and the $j$-th VIP coupon has a price $b_j$ and a parameter $c_j$. The effect of a VIP coupon with parameter $v$ is as follows:

  • If the price of the item (including souvenirs and other VIP coupons) purchased immediately after buying this coupon is $x$, the price of that item becomes $\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; 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.

Input

The input contains multiple test cases.

The first line contains a positive integer $t$ ($1\le t\le10^5$), representing the number of test cases.

For each test case:

  • The first line contains two positive integers $n,m$ ($1\le n,m\le5\cdot10^5$).

  • The second line contains $n$ integers $a_1,\ldots,a_n$ ($0\le a_i\le10^9$).

  • The third line contains $m$ integers $b_1,\ldots,b_m$ ($0\le b_i\le10^9$).

  • The fourth line contains $m$ integers $c_1,\ldots,c_m$ ($0\le c_i\le10^9$).

It is guaranteed that the sum of $n$ and $m$ over all test cases does not exceed $5\cdot10^5$.

Output

For each test case, output a single integer representing the minimum cost to purchase all souvenirs.

Examples

Input 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

Output 1

4
5

Note

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