Loading...
Loading...
Loading...
A team has a budget limit. Given n positive task costs in order, find the largest number of tasks in a row whose total cost is at most the limit. Print 0 if even one task is too expensive.
Example
Input
7 10 1 2 3 4 5 1 1
Output
4
The tasks 1 2 3 4 total 10, so 4 tasks fit.
Try the problem first. Open one hint at a time.
Add the new cost on the right. While the total is above the limit, drop costs from the left.
The length is right - left + 1; it can be 0.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor