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

int main(){
    ios_base::sync_with_stdio(0);
    cout.tie(0); cin.tie(0);
    int n; cin>>n;
    vector<int> a(n, 0);
    for(int i=0; i<n; i++){int x; cin>>x; x--; a[x]++;}
    //-----------------------
    sort(a.begin(), a.end(), greater<int>());
    //-----------------------
    int result = 0;
    int left = 0, right = n-1;
    while(left < n){
        if(a[left] != 0) result++;
        else break;
        int to_del = a[left] - 1; a[left] = 0; left++;

        while(to_del > 0 && right >= 0){
            int now = a[right];
            a[right] = max(0, a[right] - to_del);
            int r = now - a[right]; to_del -= r; if(a[right] == 0) right--;
        }
    }
    //-----------------------
    cout<<result;
}