Shopping Fever
Time limit1sMemory limit512 MB
Given n prices and a discount rate q, split the items into purchases so the total paid is minimized, where any purchase of 3 or more items gives the cheapest item free.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Greedy, Sorting, Array
- Solved
- No attempts yet
Problem
Heidi is in a big store. She would like to purchase items.
Today is her lucky day. The store runs a special sale: on every purchase, the customer receives one of the following two promotions:
- When at least items are bought together, the cheapest one is free.
- When fewer than items are bought together, the customer gets a discount on the purchase.
Heidi would like to buy all items on her shopping list, each exactly once. She can make an arbitrary number of purchases. For each purchase she'll make, the appropriate promotion will apply.
What is the minimum total price she has to pay to buy all items?
Input
The first line contains two single space-separated integers () and () — the number of items Heidi wants to buy and the percentage discount she gains for purchases of fewer than three items.
The following line contains single space separated integers — the prices of the goods (, ).
Additionally, it is guaranteed that each will always be divisible by . Hence, the discounted price of each purchase will always be an integer.
Output
Output a single integer — the minimum total price Heidi has to pay in order to buy all items.
Hint
First, Heidi can buy the three items that cost in a single transaction for (she gets one of them for free). Then she can purchase the three items that cost for (again, one is free). Finally, she can purchase the last remaining item (with cost ) with a discount.
In the second example test, if Heidi buys all three items in a single transaction, she receives discount of . However, if she buys each item individually, her discount will be .