#K50447. Maximum Prize Distribution
Maximum Prize Distribution
Maximum Prize Distribution
You are given n prizes with their corresponding beauty scores and an integer threshold T. The task is to determine the maximum number of prizes that can be awarded without the total beauty score exceeding T.
This can be formulated as finding the maximum integer k such that:
$$\sum_{i=1}^{k} b_i \le T$$
where \(b_1, b_2, \dots, b_n\) is the list of beauty scores sorted in ascending order. A greedy approach by selecting prizes with the smallest beauty scores first will yield the optimal solution.
inputFormat
The input is given via stdin and consists of three lines:
- The first line contains an integer n, representing the number of prizes.
- The second line contains n space-separated integers denoting the beauty scores of the prizes. If n is 0, this line will be empty.
- The third line contains an integer T, the maximum allowed total beauty score.
outputFormat
Output a single integer to stdout representing the maximum number of prizes that can be awarded such that their total beauty score does not exceed T.
## sample5
10 20 30 25 15
50
3
</p>