Badstrand
InterviewTime limit1sMemory limit1024 MB
Given plot prices along a coast and a budget B, find the longest contiguous run of plots whose total price is at most B.
- Level
Easy3 of 10
- Topics
- Sliding window, Array, Two pointers
- Solved
- No attempts yet
Problem
Maja is tired of the coast being taken up by large lakeside plots. She wants to build a long, nice beach that the public can use. She plans to buy a contiguous segment of plots along the coast to create the beach.
Maja has a budget of kronor. The plots along the coast cost kronor from left to right. What is the longest segment of plots that Maja can afford to buy?
Input
The first line contains two integers and , the number of plots and Maja's budget.
The second line contains positive integers (), where the -th number is the price of plot .
Output
Print one integer, the largest number of adjacent plots that Maja can afford to buy.