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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

#define N 500005

int c[N];

int main() {
    int n;
    scanf("%d", &n);

    for (int i = 0; i < n; i++) {
        int a;
        scanf("%d", &a);
        c[a]++;
    }

    vector<int> v;
    for (int i = 0; i < N; i++) {
        if (c[i] > 0) {
            v.push_back(c[i]);
        }
    }

    sort(v.begin(), v.end(), greater<int>());

    //for (auto it = v.begin(); it != v.end(); ++it) {
    //    printf("%d ", *it);
    //}

    int result = 0;

    int left = 0;
    int right = v.size();

    int sum = 0;
    while (left < right) {
        if (right - 1 > left) {
            int dostepne = v[right - 1];
            int maks = v[left] - sum - 1;
            int biore = min(dostepne, maks);

            if (biore > 0) {
                sum += biore;
                v[right - 1] -= biore;
                if (v[right - 1] == 0) {
                    right--;
                }
            }
            else {
                result++;
                left++;
                sum = 0;
            }
        }
        else {
            result++;
            left++;
        }
    }

    printf("%d", result);

    return 0;
}