Shop
Time limit2sMemory limit512 MB
Given item prices, split them into receipts so that on each receipt the cheapest floor(size/k) items are free, minimizing total payment.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Greedy, Sorting, Array
- Solved
- No attempts yet
Problem
Bill has a large family: three sons and nine grandchildren. He has to feed them all, so Bill goes to the shop once a week.
One day Bill came to the shop and saw that it was running a promotion called <<every -th item free>>. After studying the promotion rules, Bill found out the following. When the customer scans the items at the checkout, a receipt is produced. If the receipt has items, then the cheapest of them, rounded down, are free.
For example, if the receipt has five items costing 200, 100, 1000, 400, and 100 rubles respectively, and , then both items costing 100 rubles are free, and the customer has to pay 1600 rubles in total.
Bill had already chosen his items and was heading to the checkout when he realized that the items he wants to buy can be split across several receipts, and this lets him spend less money.
Help Bill find the minimum amount he can pay for the chosen items, possibly splitting them across several receipts.
Input
The first line of the input file contains two integers , (, ): the number of items Bill wants to buy and the parameter of the <<every -th item free>> promotion.
The next line contains integers (): the prices of the items Bill buys.
Output
Print a single number: the minimum amount Bill has to pay for the items.
Hint
In the example above, Bill can split the items across two receipts: one receipt contains the items costing 1000 and 400 rubles, and the item costing 400 rubles is free on that receipt, while the other receipt contains the remaining items, and one item costing 100 rubles is free there. In total Bill has to pay 1300 rubles.