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

using namespace std;

int main() {
    std::ios::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<int> arr(n);
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
    }

    sort(arr.begin(), arr.end());

    vector<int> freq;
    int count = 1;
    for (int i = 1; i < n; ++i) {
        if (arr[i] == arr[i - 1]) {
            count++;
        } else {
            freq.push_back(count);
            count = 1;
        }
    }
    freq.push_back(count);

    sort(freq.begin(), freq.end(), greater<int>());

    vector<int> sum(freq.size()+1);

    for (int i=freq.size()-1;i>=0;i--)
    	sum[i] = freq[i]+sum[i+1];

	//for (int i=0;i<freq.size();i++)	cout << freq[i]<< " ";cout << endl;
	//for (int i=0;i<sum.size();i++)	cout << sum[i]<< " ";cout << endl;

    int k = 0, sa = 0;
    while (sa < sum[k]) {
        sa += freq[k] - 1;
        k++;
    }

    cout << k << endl;

    return 0;
}