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
#include <bits/stdc++.h>
using namespace std;
int counter[500005];
int main() {
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector <int> players;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        counter[x]++;
    }
    for (int i = 1; i <= n; i++) {
        if (counter[i] != 0) 
            players.push_back(counter[i]);
    }

    sort(players.begin(), players.end());
    deque <int> q;
    for (auto p : players) {
        q.emplace_back(p);
        // cout << p;
    }

    int result = 0;
    while (q.size() > 0) {
        // cout << q.back();
        int current = q.back();
        current--;
        q.pop_back();
        result++;
        // cerr << "qsize" << q.size() <<"\n";
        while (current > 0 && q.size() > 0)
        {
            int f = q.front();
            q.pop_front();
            if (current >= f) {
                current -= f;
            }
            else {
                f -= current;
                current = 0;
                q.push_front(f);
            }
        }
    }

    cout << result << "\n";
    return 0;
}