AtCoder ABC308 F - Vouchers
Xem dạng PDF
Gửi bài giải
Điểm:
5,00 (OI)
Giới hạn thời gian:
1.0s
Giới hạn bộ nhớ:
512M
Input:
stdin
Output:
stdout
Nguồn bài:
Dạng bài
Ngôn ngữ cho phép
C, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch
Reference: AtCoder ABC308 F — Vouchers
You are going to buy ~N~ items. The regular price of the ~i~-th item is ~P_i~.
You also have ~M~ discount coupons. Coupon ~i~ may be used on an item whose regular price is at least ~L_i~. When used, it reduces the price of that item by ~D_i~.
Each coupon may be used at most once, and at most one coupon may be applied to each item.
You must buy all ~N~ items. Find the minimum possible total cost.
Input
- The first line contains two integers ~N~ and ~M~.
- The second line contains ~N~ integers: ~P_1, P_2, \ldots, P_N~.
- The third line contains ~M~ integers: ~L_1, L_2, \ldots, L_M~.
- The fourth line contains ~M~ integers: ~D_1, D_2, \ldots, D_M~.
Output
- Print one integer: the minimum total amount required.
Constraints
- ~1 \le N, M \le 2 \times 10^5~
- ~1 \le P_i \le 10^9~
- ~1 \le D_i \le L_i \le 10^9~
Example 1
Input:
3 3
4 3 1
4 4 2
2 3 1
Output:
4
Bình luận