#K83427. Minimum Number of Hospitals

    ID: 36195 Type: Default 1000ms 256MiB

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 DD, 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 DD, 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 nn, the number of patients.
• The second line contains nn space-separated integers, where each integer represents the treatment days required by a patient.
• The third line contains an integer DD, 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 DD.## sample

4
2 3 1 4
5
3

</p>