#include<bits/stdc++.h>
using namespace std;
const int lim = 500'003;
int tab[lim];
vector < int > v;
int main(){
std::ios_base::sync_with_stdio(0);
cin.tie(0);
int n, a = 0;
cin >> n;
for(int i = 0; i < n; i++){
cin >> a;
tab[a]++;
}
for(int i = 1; i <= n; i++){
if(tab[i] != 0){
v.push_back(tab[i]);
}
}
sort(v.begin(), v.end(), greater < int >());
int i = 0, j = v.size() - 1, wyn = 0;
while(i <= j){
int akt = v[i] - 1;
i++;
wyn++;
while(akt != 0 && j >= i){
if(akt >= v[j]){
akt -= v[j];
j--;
}
else {
v[j] -= akt;
akt = 0;
}
}
}
cout << wyn;
return 0;
}
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<bits/stdc++.h> using namespace std; const int lim = 500'003; int tab[lim]; vector < int > v; int main(){ std::ios_base::sync_with_stdio(0); cin.tie(0); int n, a = 0; cin >> n; for(int i = 0; i < n; i++){ cin >> a; tab[a]++; } for(int i = 1; i <= n; i++){ if(tab[i] != 0){ v.push_back(tab[i]); } } sort(v.begin(), v.end(), greater < int >()); int i = 0, j = v.size() - 1, wyn = 0; while(i <= j){ int akt = v[i] - 1; i++; wyn++; while(akt != 0 && j >= i){ if(akt >= v[j]){ akt -= v[j]; j--; } else { v[j] -= akt; akt = 0; } } } cout << wyn; return 0; } |
English