Problem library

Energy Budget

Medium
sliding window

Each ability in a rotation costs some energy, listed in costs (all positive). You want to cast the longest run of consecutive abilities whose total cost is at most budget.

Return the length of that run, or 0 if not even one ability fits.

Examples

Input: costs = [3,1,2,7,1,1], budget = 6
Output: 3
Input: costs = [9,9], budget = 5
Output: 0