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 <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    cin.tie(0)->sync_with_stdio(0);

    int n;
    cin>>n;
    int tab[n];
    for(int i=0;i<n;i++) cin>>tab[i]; 
    sort(tab, tab+n);
    vector<int>v;
    int c=1;
    for(int i=0;i<n-1;i++)
    {
        if(tab[i]==tab[i+1]) c++;
        else{v.push_back(c); c=1;}
    }
    v.push_back(c);
    sort(v.begin(), v.end());


    //for(auto i:v) cout<<i<<"\n";

    int lat=0;
    int end=v.size()-1;
    int s=0;
    while(lat<=end)
    {
        if(lat==end){
        	s++;
        	break;
        }
        int tg=v[end]-1;
        for(lat;lat<end;lat++){
        	if(tg>=v[lat]){
        		tg-=v[lat];
        		v[lat]=0;
        	}
        	else{
        		v[lat]-=tg;
        		tg=0;
        		break;
        	}
        }
        s++;
        end--;
    }
    cout<<s;
}