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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);

    int n, x[500001];
    cin>>n;
    for (int i=0; i<n; ++i)
        cin>>x[i];
    sort(x, x+n);
    x[n]=1000000;

    vector<int> l;
    for (int pocz=0, i=0; i<=n; ++i)
        if (x[i]!=x[pocz])
        {
            l.push_back(i-pocz);
            pocz=i;
        }
    sort(l.begin(), l.end());

    int wyn=0;
    for (int le=0, pr=l.size()-1; le<=pr; --pr)
    {
        ++wyn;
        int wz=l[pr]-1;
        while (0<wz)
        {
            int x=min(l[le], wz);
            l[le]-=x;
            wz-=x;
            if (l[le]==0)
                ++le;
        }
    }

    cout<<wyn<<endl;
    return 0;
}