#P10184. Interesting Days
Interesting Days
Interesting Days
Little Z has n subjects, where for the i-th subject he has exactly \(a_i\) questions. He has an infinite number of days, and on each day, he can solve as many questions as he wishes. However, Little Z considers a day to be interesting if and only if on that day he solves questions from at least \(t\) different subjects.
Since he cannot solve more than one question per subject per day (because solving more than one from the same subject does not count extra), each subject \(i\) can provide at most one contribution per day to make the day interesting.
Your task is to help Little Z determine the maximum number of interesting days possible. In other words, you have to partition the available questions into days such that each day has questions solved from at least \(t\) distinct subjects, and the total number of such days is maximized.
A key observation is that if we plan for \(d\) interesting days, then from each subject \(i\), we can use at most \(\min(a_i, d)\) questions (one per day only). Thus, a necessary and sufficient condition to achieve \(d\) interesting days is:
[ \sum_{i=1}^{n} \min(a_i, d) \ge d \times t ]
You are to calculate the maximum integer \(d\) satisfying the above inequality.
inputFormat
The input consists of two lines:
- The first line contains two space-separated integers \(n\) and \(t\), where \(n\) is the number of subjects and \(t\) is the minimum number of subjects required for an interesting day.
- The second line contains \(n\) space-separated integers \(a_1, a_2, \ldots, a_n\), where \(a_i\) represents the number of questions available for the \(i\)-th subject.
outputFormat
Output a single integer representing the maximum possible number of interesting days.
sample
3 2
1 1 1
1