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

using namespace std;


int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    sort(a.begin(), a.end());
    vector<int> b;
    int i = 0;
    while (i < a.size()) {
        int j = i;
        while (j < a.size() && a[i] == a[j]) ++j; --j;
        b.push_back(j - i + 1);
        i = j + 1;
    }
    sort(b.begin(), b.end());
    reverse(b.begin(), b.end());
    int sum = 0, cnt = 0, rest = 0;
    for (const auto& x : b) rest += x;
    for (int i = 0; i < b.size(); ++i) {
        sum += b[i];
        ++cnt;
        rest -= b[i];
        if (sum - cnt >= rest) {
            cout << cnt << endl;
            return 0;
        }
    }
    return 0;
}