A truck route is split into n segments; segment i uses fuel[i] liters of fuel (a positive integer) to traverse. A checkpoint bonus is earned by any contiguous run of segments whose total fuel usage is at least S. Find the length of the SHORTEST such run. If no contiguous run (including the entire route) reaches S, print 0.
Line 1: two integers n and S.
Line 2: n space-separated positive integers, the fuel usage per segment.
A single integer: the minimal length of a contiguous run with sum >= S, or 0 if none exists.
Example 1
Input
6 11 2 3 1 2 4 3
Expected
5
Explanation
No run of length 4 or shorter reaches 11 (the best length-4 run sums to 10), but the length-5 run [2,3,1,2,4] sums to 12, so the answer is 5.
Example 2
Input
3 100 5 5 5
Expected
0
Explanation
The entire route only sums to 15, which never reaches 100, so the answer is 0.
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 →