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
// Liderzy - 2024 Potyczki Algorytmiczne
#include <bits/stdc++.h>
using namespace std;

int main ()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    
    int n, tmp;
    cin >> n;
    vector <int> number_qty(n+1);

    for(int i = 0; i < n; ++i)
    {
        cin >> tmp;
        ++number_qty[tmp];
    }
    sort(number_qty.begin(), number_qty.end());

    // for(auto a : number_qty)
    // {
    //     cerr << a << " ";
    // }
    // cerr << endl;

    auto it = upper_bound(number_qty.begin(), number_qty.end(), 0);
    auto last_it = number_qty.end();
    int result = 0;
    while(it < last_it)
    {   
        //cerr << it - number_qty.begin() << " " << last_it-number_qty.begin() << endl;
        ++result;
        int remove_qty = (*(last_it-1))-1;
        while(remove_qty && it < last_it)
        {
            if(*it <= remove_qty)
            {
                remove_qty -= *it;
                ++it;
            }
            else
            {
                *it -= remove_qty;
                remove_qty = 0;

            }
        }
        --last_it;
    }
    cout << result;

    return 0;
}