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

using namespace std;

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

    // input
    int n;
    cin >> n;
    vector<int> a(n);
    for (int &ai : a) {
        cin >> ai;
        ai--;
    }

    // greedy
    vector<int> count(n, 0);
    for (int ai : a)
        count[ai]++;
    vector<int> tmp;
    tmp.reserve(n);
    for (int x : count)
        if (x != 0)
            tmp.push_back(x);
    swap(count, tmp);
    tmp.clear();
    sort(count.begin(), count.end());

    int ans = 0;
    int m = n;
    for (int i = count.size() - 1; i >= 0; i--) {
        m -= count[i] * 2 - 1;
        ans++;
        if (m <= 0)
            break;
    }

    // output
    cout << ans << "\n";

    return 0;
}