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
42
43
44
45
46
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;
int n, a;
map<int, int> input;
vector<int> nums;

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a;
		input[a]++;
	}

	map<int, int>::iterator it;
	for (it = input.begin(); it != input.end(); ++it) {
		nums.push_back(it->second);
	}
	sort(nums.begin(), nums.end(), greater<int>());

	int result = 0;
	int sum_smallest = 0;
	int visited = 0;
	for (int i = 0, j = nums.size() - 1; i < nums.size() && i <= j;) {
		int current_element = nums[i];
		if (i == j) {
			result++;
			break;
		}
		if (nums[j] + sum_smallest >= current_element) {
			result++;
			sum_smallest = 0;
			i++;
		}
		else {
			j--;
			sum_smallest += nums[j];
		}
	}
	cout << result;
	return 0;
}