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

const int MAXN = 5e5+7;
int a[MAXN];

bool sor(int a, int b)
{
    return a>b;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;

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

    sort(a+1, a+n, sor);

    int ans = 0;
    int st = 1, end = n;

    while(a[end] == 0)
        end--;

    while(st < end){
        int num = a[st]-1;

        while(a[end] <= num && st < end){
            num -= a[end];
            a[end] = 0;
            end--;
        }

        a[end] -= num;
        a[st] = 0;
        ans++;
        st++;
    }
    if(a[st] != 0)
        ans++;

    cout << ans;
}