#K35612. Threshold Day Finder
Threshold Day Finder
Threshold Day Finder
You are given a series of days and the amount of rainfall recorded on each day. Your task is to find the first day (0-indexed) such that the cumulative rainfall up to and including that day meets or exceeds a given threshold.
More formally, given an array \(a = [a_0, a_1, \dots, a_{n-1}]\) and an integer threshold \(T\), find the smallest index \(i\) for which
[ \sum_{j=0}^{i} a_j \ge T ]
If no such index exists, output -1
.
Note: The input is provided via stdin
and the output should be printed to stdout
. The day indices are 0-indexed.
inputFormat
The input consists of three lines:
- The first line contains a single integer (n) representing the number of days.
- The second line contains (n) space-separated integers representing the rainfall amounts for each day. If (n = 0), this line will be empty.
- The third line contains a single integer (T), the rainfall threshold.
outputFormat
Output a single integer which is the index of the first day such that the cumulative rainfall meets or exceeds (T). If no such day exists, output (-1).## sample
5
2 1 3 1 1
5
2