Question
Ser Duncan The Tall
The Lords of Westeros are testing Ser Duncan, The Tall. He faces N trials. Each trial gives him either:
-
+Xhonor points (if he succeeds), or -
-Xhonor points (if he fails).
Ser Duncan starts with 0 honor. However, a true knight never lets his honor fall below 0. If at any point his honor becomes negative, the trial ends immediately. Your task is to determine:
-
How many trials he successfully completes before his honor drops below 0.
Input
- The first line contains an integer N — the number of trials.
- The second line contains N space-separated integers representing the honor change for each trial.
Output
Print a single integer — the number of trials Ser Duncan completes before his honor drops below 0.
Example
Example 1
Input:
5
4 -2 3 -1 -5
Output
4
Explanation
Initial honor = 0
After Trial 1: 0 + 4 = 4
After Trial 2: 4 - 2 = 2
After Trial 3: 2 + 3 = 5
After Trial 4: 5 - 1 = 4
After Trial 5: 4 - 5 = -1 (Honor becomes negative)
Ser Duncan completes 4 trials before failing.
Example 2
Input
3
1 -1 -1
Output
2
Explanation
Initial honor = 0
After Trial 1: 0 + 1 = 1
After Trial 3: 0 - 1 = -1 (Honor becomes negative)
Ser Duncan completes 2 trials before failing.
Input:
5
4 -2 3 -1 -5
Output
4
Explanation
Initial honor = 0
After Trial 1: 0 + 4 = 4
After Trial 2: 4 - 2 = 2
After Trial 3: 2 + 3 = 5
After Trial 4: 5 - 1 = 4
After Trial 5: 4 - 5 = -1 (Honor becomes negative)
Ser Duncan completes 4 trials before failing.
Example 2
Input
3
1 -1 -1
Output
2
Explanation
Initial honor = 0
After Trial 1: 0 + 1 = 1
After Trial 3: 0 - 1 = -1 (Honor becomes negative)
Ser Duncan completes 2 trials before failing.