Growth multipliers
Statement
A greenhouse writes down the weight of a single sapling every day. When a day passes, the weight of the sapling is multiplied by the growth multiplier written down for that day. If the growth multiplier on some day is 1.200, the weight became 1.2 times as large over that one day, and on a day whose multiplier is below 1.000 the weight went down instead.
The greenhouse keeper holds a record of the growth multipliers over N days. The keeper wants to pick one run of consecutive days out of this record and write in a report the value found by multiplying together the growth multipliers of every day in that run. The run may be a single day, or it may be all N days. The keeper wants to write the largest value in the report.
Given the growth multipliers over N days, from day 1 to day N in order, write a program that calculates the largest value that can come out of picking one run of consecutive days and multiplying together every growth multiplier in that run.
For example, suppose the growth multipliers over N=8 days are as in the table below.
| Day | Day 1 | Day 2 | Day 3 | Day 4 | Day 5 | Day 6 | Day 7 | Day 8 |
|---|---|---|---|---|---|---|---|---|
| Growth multiplier | 1.476 | 0.742 | 0.995 | 1.491 | 1.852 | 0.736 | 0.523 | 1.016 |
For each day, finding the run of consecutive days ending on that day whose product is largest gives the table below.
| Day it ends on | Day 1 | Day 2 | Day 3 | Day 4 | Day 5 | Day 6 | Day 7 | Day 8 |
|---|---|---|---|---|---|---|---|---|
| Largest product | 1.476 | 1.095 | 1.090 | 1.625 | 3.009 | 2.215 | 1.158 | 1.177 |
The largest value in the table is 3.009, from the run that ends on day 5. That value is the result of multiplying together every multiplier from day 1 to day 5, the value of 1.476 × 0.742 × 0.995 × 1.491 × 1.852. So the answer in this example is 3.009.
Putting a day whose multiplier is below 1.000 into the run makes the product smaller, so taking a long run is not always better. Picking all of day 1 through day 8, for example, leaves the product at only 1.177. Nor can only the days whose multiplier is above 1.000 be gathered up and picked. The days in a run have to follow one another, so a day in the middle cannot be skipped.
There may also be a day whose multiplier is 0.000. Putting such a day into the run makes the product 0.000, so no run that reaches past that day can be the answer. When N is 1 there is only one run to pick, day 1, so that day's multiplier is the answer as it is.
Input and Output Examples
Example 1
Input
8 1.476 0.742 0.995 1.491 1.852 0.736 0.523 1.016
Output
3.009
Example 2
Input
5 1.1 0.5 3.2 0.1 4.0
Output
4.000
Example 3
Input
1 0.943
Output
0.943
Input
First the number of days written down N is given on the first line. N is a natural number from 1 to 10,000.
Then N lines follow, each holding the growth multiplier for one day, from day 1 to day N, one per line and in order. Each growth multiplier is a real number from 0 to 4, given to three decimal places. Fewer than three digits are sometimes written below the decimal point. For example, some are written with only one digit, such as 3.2 or 4.0.
Output
Print on one line the largest value that can come out of picking one run of consecutive days and multiplying together every growth multiplier in that run. Round the value at the fourth decimal place, rather than cutting the extra digits off, and print it to three decimal places. Even when the digits below the decimal point are zeros, do not leave them out, write all three. For example, if the answer is 4, print 4.000.
Requirements
- A run is 1 day or longer. Picking a single day counts as a run
- The days in the run you pick have to follow one another. You cannot skip a day in the middle
- Always write the answer to three decimal places. Round it at the fourth decimal place, do not cut the extra digits off
- You must write a program that reads from standard input and writes to standard output
- Trailing spaces at the end of a line and blank lines at the end of the output are ignored when grading
- The languages you can use are Python and JavaScript
- The memory limit is 256MB. The browser does not measure it, it only states it
- The time limit is set by measuring the setter's reference solution on the same runtime
- On this problem you submit code, not a prompt. That code runs in the browser on this device, and all that goes to the server is a fingerprint of the output and the time it took. Whether it is correct is decided by the server. The run time is a number each device reports, so the code and the device details are posted next to it on the leaderboard.
- The output has to match the expected value down to the character. A space inside a line counts the same as any other character.
- There are 15 cases, and 3 of them show the input together with the expected output. The rest are used only when you submit and are not shown on this page.
- You have to pass all 15 cases to solve this.
Examples
3 public cases. Judging also uses hidden cases. You have to pass all 15 cases to solve this.
1 0.943
0.943
8 1.476 0.742 0.995 1.491 1.852 0.736 0.523 1.016
3.009
5 1.1 0.5 3.2 0.1 4.0
4.000
Solution
Your code runs on this device. Only the fingerprint of the output and the elapsed time go to the server. The server decides whether it is correct.
Submitting requires you to log in. Running against the public cases works without one.
You can test with 3 public cases. Submitting runs the hidden cases too.
People who solved this problem
The time shown is the time spent solving. Input reading time is outside the solver's control, so it is excluded. And since each device reports this value itself, we record which device measured it.
Log in and you can see the code once you solve this problem.