#C6860. Maximum Number of Performances
Maximum Number of Performances
Maximum Number of Performances
Given a list of performance durations and a maximum allowable total performance time, determine the maximum number of performances that can be scheduled on a single stage without exceeding the time constraint.
Input consists of an integer (n) (the number of performances), a maximum time (T), and a list of (n) durations (d_1, d_2, \dots, d_n). The goal is to select as many performances as possible such that their total duration does not exceed (T). Formally, you need to find the maximum (k) such that
[
\sum_{i=1}^{k} d_{(i)} \le T
]
where (d_{(i)}) are the durations sorted in non-decreasing order.
Implement an efficient algorithm to solve this problem.
inputFormat
The first line contains two integers (n) and (T) where (n) is the number of performances and (T) is the maximum total allowable time. The second line contains (n) space-separated integers representing the duration of each performance.
outputFormat
Output a single integer representing the maximum number of performances that can be scheduled without the total duration exceeding (T).## sample
5 180
30 60 90 120 45
3