#P12413. 「YLLOI-R1-T2」圣诞星
「YLLOI-R1-T2」圣诞星
Description
Little Y needs to buy items in a store, and the price of the -th item is yuan.
Before buying these items, Little Y can buy as many coupons as he wants. Each coupon costs yuan. Each coupon gives a yuan discount on any item, but any item can be discounted to a minimum of yuan. (Coupons are not considered items)
After paying for each item, Little Y will also receive one more coupon.
Now Little Y wants to know the minimum amount of money needed to buy all the items.
Note: All coupons are permanent.
Input Format
The first line contains two integers and .
The second line contains integers .
Output Format
Output a single integer — the minimum amount of money Little Y needs to spend to buy all the items.
4 3
3 4 5 5
9
4 3
4 4 3 3
7
Hint
Explanation
Sample 1:
Here is an optimal solution.
First, purchase discount coupons, costing yuan.
Then, use yuan to buy the first product ( discount coupons reduced the price by yuan), and receive one more coupon.
Next, use yuan to buy the second product ( discount coupons reduced the price by yuan), and receive one more coupon.
Next, use yuan to buy the third product ( discount coupons reduced the price by yuan), and receive one more coupon.
Finally, use yuan to buy the fourth product ( discount coupons reduced the price by yuan, because the minimum discount for any product is yuan), and receive one more coupon.
Therefore, the total cost is yuan.
Sample 2:
Here is an optimal solution.
First, purchase discount coupon, costing yuan.
Then, use yuan to buy the fourth product ( discount coupon reduced the price by yuan), and receive one more coupon.
Next, use yuan to buy the third product ( discount coupons reduced the price by yuan), and receive one more coupon.
Next, use yuan to buy the second product ( discount coupons reduced the price by yuan), and receive one more coupon.
Finally, use yuan to buy the first product ( discount coupons reduced the price by yuan), and receive one more coupon.
Therefore, the total cost is yuan.
Constraints
This problem uses subtask scoring.
- Subtask 1 (10 pts): .
- Subtask 2 (10 pts): .
- Subtask 3 (20 pts): .
- Subtask 4 (30 pts): .
- Subtask 5 (30 pts): No additional constraints.
For all data:
- .
- .
京公网安备 11011102002149号