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
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

const int N = 5e5 + 3;
int tab[N];
vector <int> values;
int main()
{
    int n;
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        tab[a]++;
    }
    for(int i = 0; i < n; i++)
        if(tab[i] != 0) values.push_back(tab[i]);

    sort(values.begin(), values.end());

    int i = 0, j = values.size() - 1, wynik = 0, acc;

    while(i <= j)
    {
        wynik++;
        acc = values[j];
        while(acc - values[i] > 0 && i <= j)
        {
            acc -= values[i];
            i++;
        }
        j--;
    }
    cout << wynik;
    return 0;
}