#BS0000359. Phiếu giảm giá (Vouchers)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Phiếu giảm giá (Vouchers)
Vouchers
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
You plan to purchase items at a Japanese store. Item has a listed price of yen.
You own vouchers. Voucher is eligible for an item with a listed price of at least yen and reduces the payment for that item by 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 items.
Input
The first line contains integers , the numbers of items and vouchers.
The second line lists the integer prices .
The third line lists the integer eligibility thresholds .
The fourth line lists the integer discounts in voucher order.
Output
Print one integer: the minimum total payment in yen.
Subtasks
- Subtask 1 (20 points): ; for every ; for every ; all input values are integers.
- Subtask 2 (30 points): ; for every ; for every ; all input values are integers.
- Subtask 3 (50 points): ; for every ; for every ; 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.