AIOC Banner

Problem: Drought

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.

Drought

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.

Input

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.

Output

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

Sample Input 1

6 10
2
3
3
2
2
4

Sample Output 1

4

Sample Input 2

6 11
2
3
3
2
2
4

Sample Output 2

5

Explanation

In both examples, the total rainfall changes as follows:

DayRunning Total (in litres)
12
25
38
410
512
616

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

Scoring

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

Contact: training@orac.amt.edu.au
Page generated: 24 July 2019,  7:11pm AEST