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
#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    unordered_map<int, int> m;
    for (int i=0; i<n; i++) {
        int x;
        cin >> x;
        m[x]++;
    }
    vector<int> res;
    for (auto a : m) {
        res.push_back(a.second);
    }
    sort(res.begin(), res.end());
    int p = 0, q = res.size()-1, sumL = 0, sumR = 0, resVal = 0;
    while (p < q) {
        sumL = 0, sumR = res[q];
        while (sumL < sumR && p < q) {
            if (res[p] + sumL < sumR) {
                sumL += res[p];
                p++;
            }
            else {
                int neg = sumR - sumL - 1;
                sumL += neg;
                res[p] -= neg;
                break;
            }
        } 
        resVal++;
        q--;
    }
    if (p == q && res[p] > 0) {
        resVal++;
    }
    cout << resVal << '\n';
}