#P4960. Minimize Containers for Coagulation Factors
Minimize Containers for Coagulation Factors
Minimize Containers for Coagulation Factors
You are given a multiset of n positive integers \(a_1, a_2, \ldots, a_n\). The task is to partition these numbers into some disjoint sets \(S_1, S_2, \ldots, S_m\) such that each set satisfies one of the following conditions:
- All numbers in the set are equal. In other words, for every \(a_i, a_j \in S_k\), we have \(a_i = a_j\).
- All numbers in the set are pairwise distinct. That is, for every \(a_i, a_j \in S_k\) with \(i \neq j\), \(a_i \neq a_j\).
Your goal is to partition the numbers using as few sets (containers) as possible.
Explanation
You can think of the problem as follows: For each type (distinct number) with frequency \(f_i\), you have two ways to place its occurrences:
- Place at most one occurrence in each distinct set. If you decide to use \(K\) distinct sets then at most \(K\) occurrences of any number can be placed in them.
- If the frequency \(f_i\) is greater than \(K\), the remaining \(f_i - K\) copies must be grouped together in a homogeneous container (which counts as one container for that number).
Thus, if you use \(K\) distinct containers, the total number of containers required is:
[ m = K + \Bigl|{ i \mid f_i > K }\Bigr| ]
Your task is to choose an integer \(K\) (with \(0 \le K \le \max_i f_i\)) that minimizes \(m\). Note that choosing \(K = 0\) means you use only homogeneous containers (one per distinct number).
inputFormat
Input is given as follows:
The first line contains a single integer (n) (the number of coagulation factors).
The second line contains (n) positive integers (a_1, a_2, \ldots, a_n) separated by spaces.
outputFormat
Output a single integer representing the minimum number of containers required to partition all coagulation factors.
sample
3
1 2 3
1
</p>