#P12412. Minimizing Lonely Classes
Minimizing Lonely Classes
Minimizing Lonely Classes
In this problem, there are k cultural classes and Xiao Y has n good friends. The i-th friend plans to attend mi classes, while Xiao Y himself does not attend any classes.
The friends can adjust their course selection arbitrarily. However, they know that if all of them attend the same class at the same time, then in that class the computer lab will only have Xiao Y, making him feel lonely. In other words, a class becomes a "lonely" class for Xiao Y if every one of his n friends attends that class.
The goal is to rearrange the selections such that the number of lonely classes is minimized. Under an optimal arrangement, compute the minimum number of classes in which Xiao Y feels lonely.
A key observation is that each class, if it is not lonely, can have at most n-1 selections. Hence, all selections up to (n-1) × k can potentially be arranged so that no class is fully attended. If the total number of selections exceeds (n-1) × k, then the extra selections force exactly that many courses to become full (i.e. each such class will have all n friends attend).
The answer can be formulated in LaTeX as follows:
$$\text{answer} = \max\Bigl(0,\sum_{i=1}^{n} m_i - (n-1)\times k\Bigr) $$inputFormat
The input consists of two lines:
- The first line contains two integers k and n — the number of cultural classes and the number of friends, respectively.
- The second line contains n integers: m1, m2, ..., mn, where each mi denotes the number of classes the i-th friend plans to attend.
It is guaranteed that the values of k, n and mi are such that a valid arrangement always exists.
outputFormat
Output a single integer — the minimum number of classes in which Xiao Y will feel lonely under an optimal arrangement.
sample
5 3
3 3 3
0
</p>