The largest faculty has mx = max(g, s, h, r) students. If we try to distribute them evenly across classrooms, then at least one of the classrooms will have no fewer than \left\lceil mx / m \right\rceil students. This is the minimum number of students from a single faculty that will have to be seated in one classroom, even with an optimal arrangement.
Algorithm implementation
Read the input data.
scanf("%d %d %d %d", &g, &s, &h, &r);
scanf("%d", &m);Compute mx = max(g, s, h, r).
mx = g;
if (s > mx) mx = s;
if (h > mx) mx = h;
if (r > mx) mx = r;Let’s determine the maximum number of students that may end up in a single classroom: res = \left\lceil mx / m \right\rceil.
res = mx / m;
if (mx % m > 0) res++;Print the answer.
printf("%d\n", res);Java implementation
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner con = new Scanner(System.in);
int g = con.nextInt();
int s = con.nextInt();
int h = con.nextInt();
int r = con.nextInt();
int m = con.nextInt();
int mx = g;
if (s > mx) mx = s;
if (h > mx) mx = h;
if (r > mx) mx = r;
int res = mx / m;
if (mx % m > 0) res++;
System.out.println(res);
con.close();
}
}Python implementation
Read the input data.
a = list(map(int, input().split()))
m = int(input())Compute and print the answer.
print((max(a) - 1) // m + 1)