Longest Affordable Streak
Item prices are positive. Find the longest contiguous run of items whose total price does not exceed the budget K (possibly length 0).
Input: the first line has N and K; the second line has N positive integers.
Output: the maximum length of a contiguous run with sum ≤ K.
Constraints:
- 1 ≤ N ≤ 105
- 1 ≤ ai ≤ 104
- 1 ≤ K ≤ 109
Sample Tests
Input 1
6 8 3 1 2 5 1 1
Output 1
3
Input 2
3 1 5 6 7
Output 2
0
Discussion (opens after you solve — no spoilers before)
No comments yet.