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
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

const int MAX = 500008;

int main () {
	int n;
	scanf("%d", &n);
	vector<int> cnt(MAX, 0);
	for (int i = 0; i < n; ++i) {
		int x;
		scanf("%d", &x);
		++cnt[x];
	}
	vector<pair<int, int> > items;
	items.reserve(n + 8);
	for (int i = 0; i < MAX; ++i) {
		for (int j = 0; j < cnt[i]; ++j) {
			items.push_back(make_pair(cnt[i], i));
		}
	}
	sort(items.begin(), items.end(), greater<pair<int, int> >());
	int l = 0;
	int r = n - 1;
	int seq = 0;
	while (l <= r) {
		int size = items[l].first;
		l += size;
		r -= size - 1;
		++seq;
	}
	printf("%d\n", seq);
	return 0;
}