Frosting CupcakesProblem code: MUFFINS2 |
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
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.
Output
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.
Sample input
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
Sample output
3.66667 0.62500 0.40000 2.00000
Constraints
T<501?N?30000
0?S?30000
0?Ci?20000
At least one Ci will be non-zero
| Author: | pieguy |
| Date Added: | 29-03-2011 |
| Time Limit: | 3 sec |
| Source Limit: | 50000 Bytes |
| Languages: | ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, ERL, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC |
Comments
SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:
HELP
Program should read from standard input and write to standard output. After you submit a solution you can see your results by clicking on the [My Submissions] tab on the problem page. Below are the possible results:
- Accepted
Your program ran successfully and gave a correct answer. If there is a score for the problem, this will be displayed in parenthesis next to the checkmark. - Time Limit Exceeded
Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach. - Wrong Answer
Your program compiled and ran succesfully but the output did not match the expected output. - Runtime Error
Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section. - Compilation Error
Your code was unable to compile. When you see this icon, click on it for more information.
If you are still having problems, see a sample solution here.

Fetching successful submissions
