A community reserve fund receives n daily contributions on days 1..n (a contribution may be negative, representing a withdrawal). Given a target amount T, find the earliest day index i (1-indexed) such that the sum of contributions from day i through day n (inclusive) is greater than or equal to T. If no such day exists, print -1.
Line 1: two integers n T.
Line 2: n space-separated integers, the contributions for day 1, day 2, ..., day n.
A single integer: the smallest day index i whose suffix sum (day i to day n) is >= T, or -1 if none exists.
Example 1
Input
5 10 3 -2 8 1 4
Expected
1
Explanation
The suffix sum starting at day 1 is 3-2+8+1+4=14, which already meets the target of 10, so day 1 qualifies immediately.
Example 2
Input
6 20 -100 5 5 5 5 5
Expected
2
Explanation
Day 1's suffix sum is -100+25=-75 (too low). Day 2's suffix sum is 5+5+5+5+5=25, which meets the target of 20, so the answer is day 2.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →