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
57
58
59
60
61
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

    int tmp;
    vector<int> arr;
    arr.reserve(n+5);
    for(int i = 0 ; i < n+5 ; i ++)
    {
        arr.push_back(0);
    }

    for(int i = 0 ; i < n ; i ++)
    {
        cin>>tmp;
        arr[tmp] ++;
    }

    vector<int> list;

    for(int i = 0 ; i < arr.size() ; i ++)
    {
        if( arr[i] > 0 )
        {
            // cerr<<i<<" - "<<arr[i]<<endl;
            list.push_back(arr[i]);
        }
        
    }

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

    int liders = 0;
    int rest = 0;

    int ans = 0;

    for(int i = list.size() -1 ; i >=0 ; i -- )
    {
        liders += list[i];
        rest += list[i]-1;

        ans += 1;

        if( liders + rest >= n)
        {
            break;
        }
    }

    cout<<ans<<endl;


}