A total of s = \sum_{i=1}^n a_i participants arrived at the competition. Since each classroom is equipped with computers, at least rooms are required.
Let be the largest number of participants in a single team (the maximum among all values a_i). If p > ⌈s/m⌉, then at least rooms are needed.
It can be shown constructively that it is always sufficient to have max(⌈s/m⌉, p) classrooms to conduct the olympiad.
Example
A total of 2 + 3 + 4 + 1 + 2 = 12 students arrived at the olympiad. Since each classroom is equipped with computers, at least 12 / 3 = 4 classrooms are required.
The largest team is the third one, with participants. They can be seated one by one in different classrooms.
For example, the following seating arrangement is possible:
Algorithm implementation
Read the input data.
scanf("%d %d",&n,&m);Compute the total number of participants , as well as the size of the largest team.
p = 0;
for (i = 0; i < n; i++)
{
scanf("%d",&x);
s += x;
if (x > p) p = x;
}The value res = ⌈s/m⌉ is computed as (s + m - 1) / m.
res = (s + m - 1) / m;If p > ⌈s/m⌉, then the answer is .
if (res < p) res = p;Print the answer.
printf("%d\n",res);