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
#include <stdio.h>
#include <unordered_map>
#include <vector>
#include <functional>

using namespace std;

int N;
unordered_map<int, int> U;
vector<int> V;
int main() {
    scanf("%d",&N);
    for (int i=0;i<N;++i) {
        int v;
        scanf("%d",&v);
        if (!U.contains(v)) {
            U[v] = 1;
        } else {
            U[v] = U[v] + 1;
        }
    }

    
    for (const auto& [key, value] : U)
        V.push_back(value);
        //printf(" %d => %d ",key, value);
    sort(V.begin(),V.end());
    int R = 0;
    int left = N;
    for (auto riter = V.rbegin();riter != V.rend(); ++riter) 
    { 
         int v = *riter;
         R++;
         left -= v;
         left -= (int)(v-1);
         if (left<=0) {
            break;
         }
    } 
    printf("%d\n",R);
    return 0;
}