#K55312. Maximum Movies
Maximum Movies
Maximum Movies
You are given a list of movie durations and a total available time m (in minutes). The goal is to determine the maximum number of movies that can be viewed in full, by watching movies starting from the shortest duration. Formally, if you sort the movie durations in ascending order as \(L_1, L_2, \ldots, L_n\), you need to find the maximum integer \(k\) such that \(\sum_{i=1}^{k}L_i \le m\).
This problem requires an efficient greedy approach: sort the list and iterate until the running total exceeds the available time.
inputFormat
The first line contains two integers n and m, where n is the number of movies and m is the total available minutes. The second line contains n space-separated integers representing the durations of the movies.
outputFormat
Output a single integer: the maximum number of movies that can be fully watched.
## sample4 300
120 90 150 80
3
</p>