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
47
48
49
50
#include<iostream>
#include <vector>
#include <map>
#include <algorithm> 
#include <bits/stdc++.h>
using namespace std;



int main()
{
	//dodac magiczne linijki, /n, inline, &1
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
	int n; cin >> n;
	vector<int> wystepowania(500001, 0);
	int max = -1;
	int elem;
	for (int i = 0 ; i < n ; ++i)
	{
		cin >> elem;
		++wystepowania[elem];
		if (elem > max)
			max = elem;
	}
	wystepowania.resize(max+1);
	sort(wystepowania.begin(), wystepowania.end(), greater<int>());
	//dziala?
	auto pointerRight = wystepowania.end() - 1;
	while (*pointerRight == 0)
		--pointerRight;
	auto pointerLeft = wystepowania.begin();
	int counter = 0;
	while (pointerLeft < pointerRight)
	{
		if (*pointerLeft > *pointerRight)
		{
			*pointerLeft -= *pointerRight;
			--pointerRight;
		}
		else
		{
			*pointerRight -= *pointerLeft-1;
			++pointerLeft;
			++counter;
		}
	
	}
	cout << counter + (pointerLeft == pointerRight);
}