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
//
// Created by piotr on 11.03.2024.
//
#include <algorithm>
#include <cstdio>
#include <vector>

int main()
{
    int N;
    std::vector<int> numbers;
    scanf("%d", &N);
    numbers.resize(N);
    for (int& number : numbers) {
        scanf("%d", &number);
    }

    std::sort(numbers.begin(), numbers.end());

    std::vector<int> counts;
    counts.reserve(N);
    int prev_number = 0;
    for (int number : numbers) {
        if (number == prev_number) {
            counts.back()++;
        } else {
            counts.push_back(1);
            prev_number = number;
        }
    }

    std::sort(counts.begin(), counts.end());
    auto i_small = counts.begin();
    auto i_large = counts.end() - 1;

    int result = 0;
    do {

        int max_left = *i_large - 1;
        *i_large-- = 0;
        while (i_small <= i_large && max_left > 0) {
            if (*i_small <= max_left) {
                max_left -= *i_small;
                *i_small++ = 0;
            } else {
                *i_small -= max_left;
                max_left = 0;
            }
        }
        ++result;

    } while (i_small <= i_large);

    printf("%d\n", result);

}