Pastry shop
Time limit2sMemory limit128 MB
For each oven baking time d, find the minimum total customer waiting time when pies are baked one at a time, starting at time 0.
- Level
Hard9 of 10
- Topics
- Dynamic programming, Divide and conquer, Greedy
- Solved
- No attempts yet
Problem
You are the owner of a pastry shop that bakes the best pies in town. Every day, customers come to your shop, and the -th customer arrives at time . You can start baking a pie at time 0. After arriving, a customer waits until you serve the favourite pie straight out of the oven. Nobody likes cold pies, so a customer may wait for a pie, but a pie must not wait for a customer.
Your oven can bake only one pie at a time and cannot be opened during baking. Every pie takes the same time to bake. You know the arrival time of each customer in advance, so you schedule the baking to minimize the total waiting time of the customers.
Your current oven is worn out, so you are thinking about buying a new one. You have chosen oven models. The duration of baking one pie in the -th model is . You want the fastest oven, but you are not sure whether you can afford it. For each model, compute the total time the customers would wait if you bought that oven and scheduled the baking optimally.
Input
The first line contains two integers and (). The second line contains integers (). Two customers can arrive at the same time. The third line contains integers ().
Output
Print exactly lines. The -th line contains one integer, the minimum total waiting time of the customers when the -th oven model is used with optimal baking.