#K50062. Consecutive Movie Marathon

    ID: 28781 Type: Default 1000ms 256MiB

Consecutive Movie Marathon

Consecutive Movie Marathon

You are given a list of movies where each movie has a certain duration, and an integer limit. Your task is to determine the maximum number of consecutive movies that can be watched such that the total duration does not exceed the given limit. Formally, given an array of integers representing movie durations, find the largest integer ( k ) such that there exists an index ( i ) for which ( \sum_{j=i}^{i+k-1} \text{movies}[j] \leq \text{limit} ). This problem can be effectively solved using the sliding window technique.

inputFormat

The first line contains two integers ( N ) and ( limit ), where ( N ) is the number of movies. The second line contains ( N ) space-separated integers representing the duration of each movie.

outputFormat

Output a single integer representing the maximum number of consecutive movies whose total duration does not exceed ( limit ).## sample

6 400
100 200 150 300 50 100
2

</p>