PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000359. Phiếu giảm giá (Vouchers)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Phiếu giảm giá (Vouchers)

Vouchers

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

You plan to purchase NN items at a Japanese store. Item ii has a listed price of PiP_i yen.

You own MM vouchers. Voucher jj is eligible for an item with a listed price of at least LjL_j yen and reduces the payment for that item by DjD_j yen.

A voucher may be redeemed at most once, and an item may receive at most one voucher. Items without a voucher cost their listed price. Unused vouchers are allowed.

Determine the least total payment for purchasing all NN items.

Input

The first line contains integers N,MN,M, the numbers of items and vouchers.

The second line lists the NN integer prices P1,P2,…,PNP_1,P_2,\ldots,P_N.

The third line lists the MM integer eligibility thresholds L1,L2,…,LML_1,L_2,\ldots,L_M.

The fourth line lists the MM integer discounts D1,D2,…,DMD_1,D_2,\ldots,D_M in voucher order.

Output

Print one integer: the minimum total payment in yen.

Subtasks

  • Subtask 1 (20 points): 1≤N,M≤81\le N,M\le 8; 1≤Pi≤1091\le P_i\le 10^9 for every 1≤i≤N1\le i\le N; 1≤Di≤Li≤1091\le D_i\le L_i\le 10^9 for every 1≤i≤M1\le i\le M; all input values are integers.
  • Subtask 2 (30 points): 1≤N,M≤20001\le N,M\le 2000; 1≤Pi≤1091\le P_i\le 10^9 for every 1≤i≤N1\le i\le N; 1≤Di≤Li≤1091\le D_i\le L_i\le 10^9 for every 1≤i≤M1\le i\le M; all input values are integers.
  • Subtask 3 (50 points): 1≤N,M≤2⋅1051\le N,M\le 2\cdot10^5; 1≤Pi≤1091\le P_i\le 10^9 for every 1≤i≤N1\le i\le N; 1≤Di≤Li≤1091\le D_i\le L_i\le 10^9 for every 1≤i≤M1\le i\le M; all input values are integers.

Examples

Input 1

3 3
4 3 1
4 4 2
2 3 1

Output 1

4

Explanation 1

Apply voucher 2 to the item priced 4 and voucher 3 to the item priced 3, paying 1 and 2 yen. The item priced 1 costs 1 yen. The two vouchers with threshold 4 compete for the sole eligible item, so the largest combined discount is 3+1=4. The original total 8 becomes 4 yen.

Input 2

10 5
9 7 1 5 2 2 5 5 7 6
7 2 7 8 2
3 2 4 1 2

Output 2

37

Explanation 2

The listed prices sum to 49 yen. Redeem vouchers 1 and 3 on the two items priced 7, voucher 4 on the item priced 9, and vouchers 2 and 5 on the two items priced 2. All five vouchers are used, giving the largest possible total discount of 3+4+1+2+2=12 yen. The payment is 49−12=37 yen.