Want to try solving this problem? You can submit your code online if you log in or register.

*
The problems in this set are designed to be more accessible to beginning coders. As a learning aid, walkthroughs discussing how to solve the problems in this set are available by clicking on this link.
On completion of this problem set, students should be able to use loops (for example while and for loops) to simulate processes and analyse large data sets.
*

**Input File:** `rainin.txt`

**Output File:** `rainout.txt`

**Time Limit:** 1 second

Years of drought have hit rural Australia hard. With catchment levels at an all time low, you decide to purchase a rainwater tank. Soon the winter rains arrive, and the tank slowly begins to fill.

You begin to wonder just when your tank will be entirely full. A friend in the weather bureau has kindly lent you rainfall predictions for the next few days. Given these predictions, and the size of your rainwater tank, write a program to determine how many days your tank takes to fill.

The first line of the input file will be of the form *n c*, where *n* is the number of days the weather predictions last, and *c* is the capacity of your rainwater tank in litres. You are guaranteed that 1 <= *n* <= 1,000, and that *c* is a positive integer no greater than the total amount of rain that falls over the *n* days.

The remaining *n* lines of input will describe the rainfall levels for each day in order.
Each line will contain a single integer between 0 and 1,000,000: the amount of rain (in litres) that will fall over your rainwater tank that day.

Your output should consist of a single integer: the number of days until your rainwater tank fills.

6 10 2 3 3 2 2 4

4

6 11 2 3 3 2 2 4

5

In both examples, the total rainfall changes as follows:

Day | Running Total (in litres) |
---|---|

1 | 2 |

2 | 5 |

3 | 8 |

4 | 10 |

5 | 12 |

6 | 16 |

Hence a 10-litre water tank is full after 4 days and an 11-litre water tank is full after 5 days.

The score for each input file will be 100% if the correct answer is written to the output file and 0% otherwise.

Privacy
statement

© Australian Mathematics Trust 2001-2019

Page generated: 24 July 2019, 7:11pm AEST