1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {

	int n; cin >> n;
	vector<int> counters(n);
	int a;
	for (int i = 0; i < n; i++) {
		cin >> a;
		counters[a - 1]++;
	}

	vector<int> ciagi;
	for (int i = 0; i < counters.size(); i++) {
		if (counters[i] != 0) {
			ciagi.push_back(counters[i]);
		}
	}
	sort(ciagi.begin(), ciagi.end());

	int i = ciagi.size(), j = -1, res = 0, sum = 0;

	while (j+1 < i) {
		i--;
		sum = 0;
		//cout << "Lider grupy wystepuje " << ciagi[i] << " razy." << endl;
		while (sum + ciagi[j + 1] < ciagi[i]) {
			//cout << "Do wziecia w sumie jest element " << ciagi[j + 1] << endl;
			j++;
			sum += ciagi[j];
		}
	}

	cout << ciagi.size() - i << endl;

	return 0;
}