Back to problems Sign in to unlock
Codeforces
Medium
Arrays
Sorting
Greedy
Dishonest Sellers
Buy exactly items at their first-price or second-price values so that the total cost is minimum.
Acceptance 0%
Problem Statement
You are given items. For each item , there are two possible prices: a normal price and a discounted price . You must buy exactly items at the normal price and all remaining items at the discounted price.
Your task is to choose which items to buy at the normal price so that the total amount paid is as small as possible.
Input Format
Input
- The first line contains two integers and .
- The second line contains integers .
- The third line contains integers .
Interpretation
- Item costs if bought at the normal price.
- Item costs if bought at the discounted price.
- Exactly items must be purchased at the normal price.
Output Format
Output
- Print one integer: the minimum total cost achievable.
Constraints
- Values are integers and may be large enough that a 64-bit integer is needed for the answer.
Examples
Sample cases returned by the problem API.
Example 1
Input
3 1 10 20 30 5 10 25
Output
45
Explanation
If item 1 is bought at the normal price, the total is . Choosing item 2 or 3 instead gives a larger total.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.
Guided hints
Editorial and discussion links
Concept map and variants
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.