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
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n;
    cin >> n;

    int arr[500005] = {};

    int a;
    for (int i = 0; i < 500005; i++) {
        arr[i] = 0;
    }

    for (int i = 0; i < n; i++) {
        cin >> a;
        arr[a]++;
    }
/*
    cout << "Before sorting\n";
    for (int i = 0; i <= n; ++i) {
        cout << arr[i] << " ";
        cout << endl;
    }
*/
    sort(arr, arr + n + 1);
/*
    cout << "After sorting\n";
    for (int i = 0; i <= n; ++i) {
        cout << arr[i] << " ";
        cout << endl;
    }
*/
    int numberOfLeaders = 0, sum = 0, k = n;
    while (sum < n / 2 + 1 && k > 0) {
        sum += arr[k];
        numberOfLeaders++;
        k--;
    }

    cout << numberOfLeaders << endl;

    return 0;
}