#K83427. Minimum Number of Hospitals
Minimum Number of Hospitals
Minimum Number of Hospitals
In this problem, you are given a list of patients, where each patient requires a certain number of days for treatment. You are also given an integer , which represents the maximum total treatment days that a single hospital can accommodate. The goal is to assign patients to hospitals in such a way that the sum of treatment days for all patients in any hospital does not exceed , and you want to use as few hospitals as possible.
Patients can be rearranged arbitrarily. A greedy strategy that sorts the treatment days in ascending order and then assigns each patient to an existing hospital (if possible) or opens a new one is an effective approach. Your task is to compute the minimum number of hospitals required under these conditions.
inputFormat
The input is read from standard input (stdin) and has the following format:
• The first line contains an integer , the number of patients.
• The second line contains space-separated integers, where each integer represents the treatment days required by a patient.
• The third line contains an integer , the maximum allowed total treatment days per hospital.
outputFormat
Output a single integer to standard output (stdout) representing the minimum number of hospitals required such that the cumulative treatment days assigned to any hospital do not exceed .## sample
4
2 3 1 4
5
3
</p>