Given an integer array durations where durations[i] is the duration of the i-th show, and an integer time_limit representing the total time available, return the maximum number of shows you can watch without exceeding the time limit.
You may watch shows in any order, but each show must be watched in full.
Function Signature
def max_shows(durations: List[int], time_limit: int) -> int:
Rules
-
Each entry of
durations
is a separate show and can be watched at most once.
-
A total watching time equal to
time_limit
does not exceed the limit, so it is allowed.
Constraints
-
1 <= durations.length <= 10^5
-
1 <= durations[i] <= 10^4
-
0 <= time_limit <= 10^9
Examples
Input: durations = [30,60,45,20,90], time_limit = 100
Output: 3
Sorted, the durations are [20, 30, 45, 60, 90]. The shows of length 20, 30 and 45 sum to 95, which fits within 100. Any four shows take at least 20 + 30 + 45 + 60 = 155, so four is impossible.
Input: durations = [50,50,50], time_limit = 40
Output: 0
Every show is longer than the time limit, so no show can be watched.
Input: durations = [25,10,40,10], time_limit = 45
Output: 3
The shows of length 10, 10 and 25 sum to exactly 45, which is allowed. Adding the show of length 40 would bring the total to 85.