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

const int MAX = 500005;

int n;
int K[MAX];

int main() {
    std::ios_base::sync_with_stdio(0);
    std::cin >> n;
    for (int i=0;i<n;++i) {
        int a;
        std::cin >> a;
        ++K[a-1];
    }
    std::sort(K,K+n);
    int r = n-1;
    int l = 0;
    int v = 0;
    int acc = 0;
    while (l <= r && K[r] > 0) {
        if (acc == 0) {
            acc = K[r]-1;
            --r;
            ++v;
        }
        else if (K[l] <= 0) ++l;
        else if (K[l]) {
            int diff = std::min(K[l], acc);
            acc -= diff;
            K[l] -= diff;
        }
    }
    std::cout << v << std::endl;
    return 0;
}