Miraculous Drug
InterviewTime limit1sMemory limit256 MB
Each hour uses the cheapest enzyme bought within the last h hours, breaking ties toward the latest hour, and reports purchase counts over a given interval.
- Level
Medium4 of 10
- Topics
- Sliding window, Queue
- Solved
- No attempts yet
Problem
Joe is a biomedical researcher. He is close to a cure for a terrible disease. Making the drug requires a special enzyme that is expensive and loses its properties after a fixed time. The clinical trial phase needs one dose of the drug every hour, and one dose takes one enzyme.
Prices are given for the next hours. At hour Joe can buy any number of enzymes at price each. An enzyme lives for hours, so an enzyme bought at hour can be used at hours through . Joe uses one enzyme at each of the hours through . Find the plan with the smallest total cost.
When prices tie, Joe buys the fresher enzyme instead of stocking one early. That fixes a single plan: the enzyme used at hour is bought at the cheapest hour of the interval , and if several hours are cheapest, at the latest of them.
Input
The input holds several data sets and ends at end of file. Each data set holds the number of hours , the enzyme lifetime , the first hour and the last hour of the printing interval, and then the prices , in that order. White space and line breaks may appear freely between numbers.
Output
For each data set print one line, starting at the beginning of the line, with the number of enzymes Joe buys at each of the hours through , separated by tab characters.