#K4621. Maximum Employees with Bonus

    ID: 27926 Type: Default 1000ms 256MiB

Maximum Employees with Bonus

Maximum Employees with Bonus

You are given a company with n employees and a bonus budget k. Each employee requires a certain bonus amount. Your task is to determine the maximum number of employees that can be awarded a bonus such that the total bonuses do not exceed the given budget.

The approach is to sort the bonus amounts in ascending order and then award bonuses greedily until the budget is exhausted. Mathematically, if we have bonus requirements \( s_1, s_2, \dots, s_n \) sorted in increasing order, then we want the maximum \( m \) such that \[ \sum_{i=1}^{m} s_i \leq k. \]

Note that the problem requires reading input from standard input (stdin) and writing the answer to standard output (stdout).

inputFormat

The first line contains two integers ( n ) and ( k ), where ( n ) is the number of employees and ( k ) is the total bonus budget. The second line contains ( n ) space-separated integers representing the bonus amount each employee requires.

outputFormat

Output a single integer representing the maximum number of employees that can receive the bonus without exceeding the budget.## sample

4 100
30 20 10 40
4