All submissions for this problem are available.
Now that Chef has streamlined his cupcake baking procedure,
he's turning his attention toward frosting the cupcakes.
He recently purchased a machine that produces frosting.
Each cupcake requires one unit of frosting, and the frosting machine
requires K2 units of energy to produce K units of frosting
in one minute (K need not be an integer).
Cupcakes arrive in batches, once per minute, needing frosting.
The cupcakes must be frosted within a minute of when they arrive.
The frosting machine also has a reserve unit, so it can produce extra frosting
to be used later.
The reserve unit has a capacity of S units of frosting, and is initially empty.
The machine may produce more units of frosting than is currently demanded, and
the excess will be added to the reserve unit.
Or, the machine can produce fewer units of frosting than is currently demanded,
drawing the remainder of what is needed from the reserve.
At all times the reserve unit must have between 0 and S units of frosting.
Chef has a schedule ahead of time of exactly how many cupcakes
will arrive each minute needing frosting, and can create a frosting production schedule for the machine that will optimize its energy usage. The machine may produce a different amount of frosting each minute.
Given the cupcake schedule, calculate the minimum energy needed to frost all
the cupcakes divided by the total number of cupcakes.
Input will begin with an integer T, the number of test cases.
Each test case begins with 2 integers N and S on a line, representing
the number of minutes the machine will operate, and the capacity of the
storage unit, respectively.
Following is a line with N space-separated integers C0...CN-1,
where Ci is the number of cupcakes arriving at time i.
For each test case, output on a single line the minimum total energy consumption
of the machine divided by the total number of cupcakes, rounded to 5 places after the decimal point.
4 5 0 1 2 3 4 5 5 1 0 0 0 0 2 5 2 0 0 0 0 2 5 2 2 0 0 0 0
3.66667 0.62500 0.40000 2.00000
At least one Ci will be non-zero
|Tags||cook09, hard, pieguy|
|Time Limit:||0.3625 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, PYP3, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.