#K48457. Landmark Renovation
Landmark Renovation
Landmark Renovation
You are given a city with N landmarks and a renovation budget of B. Each landmark has an associated renovation cost. Your task is to determine the maximum number of landmarks that can be renovated without exceeding the budget.
Formally, given a list of costs \( c_1, c_2, \dots, c_N \), you need to choose a subset of these landmarks such that the total cost \( \sum_{i=1}^{k} c_i \) (after sorting the costs in ascending order) does not exceed \( B \). That is, find the maximum integer \( k \) for which $$ \sum_{i=1}^{k} c_i \le B, $$ where the costs \( c_i \) are considered in non-decreasing order.
This problem requires an efficient greedy approach by sorting the renovation costs first.
inputFormat
The input is given via standard input (stdin). The first line contains two integers, (N) and (B), separated by a space, where (N) is the number of landmarks and (B) is the available budget. The second line contains (N) space-separated integers representing the renovation cost of each landmark.
outputFormat
The output should be written to standard output (stdout) and consist of a single integer representing the maximum number of landmarks that can be renovated without exceeding the budget.## sample
5 100
20 10 30 50 40
4