Sale!
Time limit2sMemory limit1024 MB
Given n book prices, a delivery fee e, and w free books per qualifying order, find the minimum total cost to buy all books for each q from 1 to n.
- Level
Medium7 of 10
- Topics
- Sorting, Greedy, Prefix sum, Math
- Solved
- No attempts yet
Statement
Doctor Strange likes to read and study new spells. His favorite bookstore, 'Dormammu', is having a sale! But the doctor is stuck in a time loop and has no time, so he decided to order all the books online for delivery.
The doctor plans to buy distinct books. During the sale, when buying or more books, the cheapest of them are free. Delivery of one order costs coins. The doctor can order a set of distinct books that are not in any other order. There is no limit on the number of books in one order.
The doctor forgot the value of . For each from to , find the minimum number of coins needed to buy all books.
Input
The first line contains three integers , , and : the number of books, the delivery cost, and the number of free books (; ).
Each of the next lines contains , the price of the -th book ().
Output
Print numbers: the minimum number of coins needed to buy all books for each from to .