#K7106. Maximum Dishes Order
Maximum Dishes Order
Maximum Dishes Order
Given a list of dish costs and a threshold value \(t\), determine the maximum number of dishes that can be added to a single order without exceeding \(t\). You must select dishes in such a way that the cumulative cost remains within the threshold.
To achieve this, sort the dish costs in ascending order and then add the smallest cost dishes one by one until the next addition would exceed \(t\).
Mathematical Formulation: For sorted dish costs \(a_1, a_2, \dots, a_n\), find the largest integer \(k\) such that \(a_1 + a_2 + \dots + a_k \le t\).
inputFormat
The input is given via standard input (stdin). The first line contains two integers \(n\) and \(t\):
- \(n\) – the number of dishes
- \(t\) – the maximum allowed total cost (threshold)
If \(n > 0\), the second line contains \(n\) space-separated integers representing the cost of each dish. If \(n = 0\), the second line is omitted.
outputFormat
Output a single integer to standard output (stdout) representing the maximum number of dishes that can be ordered without the total cost exceeding \(t\).
## sample5 10
1 2 3 4 5
4