#include <bits/stdc++.h>
using namespace std;
int tab[500100];
int n;
int main(){
ios_base::sync_with_stdio(0);
cin>>n;
for(int i=1;i<=n;i++){
int x;
cin>>x;
tab[x]++;
}
sort(tab+1,tab+n+1, greater<int>());
int pocz = 1;
int kon = n;
int wynik = 0;
while(pocz < kon && tab[pocz] != 0){
int slots = tab[pocz] - 1;
wynik++;
while(slots > 0 && pocz < kon){
int taken = min(slots, tab[kon]);
slots -= taken;
tab[kon] -= taken;
if(tab[kon] == 0) kon--;
}
pocz++;
}
if(tab[pocz] != 0) wynik++;
cout<<wynik;
}
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 | #include <bits/stdc++.h> using namespace std; int tab[500100]; int n; int main(){ ios_base::sync_with_stdio(0); cin>>n; for(int i=1;i<=n;i++){ int x; cin>>x; tab[x]++; } sort(tab+1,tab+n+1, greater<int>()); int pocz = 1; int kon = n; int wynik = 0; while(pocz < kon && tab[pocz] != 0){ int slots = tab[pocz] - 1; wynik++; while(slots > 0 && pocz < kon){ int taken = min(slots, tab[kon]); slots -= taken; tab[kon] -= taken; if(tab[kon] == 0) kon--; } pocz++; } if(tab[pocz] != 0) wynik++; cout<<wynik; } |
English