#K401. Maximum Features Approval

    ID: 26567 Type: Default 1000ms 256MiB

Maximum Features Approval

Maximum Features Approval

You are given an integer n representing the number of feature requests and an integer C which is the maximum allowed complexity. Additionally, you are provided with a list of n integers; each integer represents the complexity of a feature. Your task is to determine the maximum number of features that can be approved such that the sum of their complexities does not exceed the limit C.

Approach: A greedy strategy works well; sort the list of complexities and then select features sequentially until adding another feature would exceed the complexity limit. Mathematically, if the sorted complexities are \(a_1 \le a_2 \le \ldots \le a_n\), then find the maximum \(k\) such that \(\sum_{i=1}^{k} a_i \leq C\).

inputFormat

The input is given via standard input (stdin) and consists of two lines. The first line contains two space-separated integers, (n) and (C), where (n) is the number of feature requests and (C) is the complexity limit. The second line contains (n) space-separated integers representing the complexity ratings of the features.

outputFormat

Output via standard output (stdout) a single integer representing the maximum number of features that can be approved without exceeding the complexity limit.## sample

5 10
1 2 3 4 5
4