#P12413. 「YLLOI-R1-T2」圣诞星

    ID: 11806 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>贪心二分三分洛谷原创O2优化排序洛谷月赛

「YLLOI-R1-T2」圣诞星

Description

Little Y needs to buy nn items in a store, and the price of the ii-th item is aia_i yuan.

Before buying these items, Little Y can buy as many coupons as he wants. Each coupon costs ww yuan. Each coupon gives a 11 yuan discount on any item, but any item can be discounted to a minimum of 00 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 nn and ww.

The second line contains nn integers aia_i.

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 33 discount coupons, costing 3×3=93 \times 3 = 9 yuan.

Then, use 00 yuan to buy the first product (33 discount coupons reduced the price by 33 yuan), and receive one more coupon.

Next, use 00 yuan to buy the second product (44 discount coupons reduced the price by 44 yuan), and receive one more coupon.

Next, use 00 yuan to buy the third product (55 discount coupons reduced the price by 55 yuan), and receive one more coupon.

Finally, use 00 yuan to buy the fourth product (66 discount coupons reduced the price by 55 yuan, because the minimum discount for any product is 00 yuan), and receive one more coupon.

Therefore, the total cost is 9+0+0+0+0=99 + 0 + 0 + 0 + 0 = 9 yuan.

Sample 2:

Here is an optimal solution.

First, purchase 11 discount coupon, costing 1×3=31 \times 3 = 3 yuan.

Then, use 22 yuan to buy the fourth product (11 discount coupon reduced the price by 11 yuan), and receive one more coupon.

Next, use 11 yuan to buy the third product (22 discount coupons reduced the price by 22 yuan), and receive one more coupon.

Next, use 11 yuan to buy the second product (33 discount coupons reduced the price by 33 yuan), and receive one more coupon.

Finally, use 00 yuan to buy the first product (44 discount coupons reduced the price by 44 yuan), and receive one more coupon.

Therefore, the total cost is 3+2+1+1+0=73 + 2 + 1 + 1 + 0 = 7 yuan.

Constraints

This problem uses subtask scoring.

  • Subtask 1 (10 pts): ai=i\forall a_i = i.
  • Subtask 2 (10 pts): w=1w = 1.
  • Subtask 3 (20 pts): n,ai,w10n, a_i, w \leq 10.
  • Subtask 4 (30 pts): n,ai,w1000n, a_i, w \leq 1000.
  • Subtask 5 (30 pts): No additional constraints.

For all data:

  • 1n1051 \leq n \leq 10^5.
  • 1ai,w1091 \leq a_i, w \leq 10^9.