#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, a;
cin>>n;
vector<int> zliczanie(n+1, 0);
for(int i=0; i<n; i++){
cin>>a;
zliczanie[a]++;
}
vector<int> ciag;
for(int i=0; i<n+1; i++){
if(zliczanie[i]!=0) ciag.push_back(zliczanie[i]);
}
sort(ciag.begin(), ciag.end());
vector<bool> marked(ciag.size(), false);
int wyn=0;
int k=0;
for(int i=ciag.size()-1; i>=0; i--){
if(marked[i]) break;
for(; ciag[i]>ciag[k]; k++){
ciag[i]-=ciag[k];
marked[k]=true;
}
ciag[k]-=ciag[i]-1;
marked[i]=true;
wyn++;
}
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 43 | #include <bits/stdc++.h> using namespace std; typedef long long LL; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, a; cin>>n; vector<int> zliczanie(n+1, 0); for(int i=0; i<n; i++){ cin>>a; zliczanie[a]++; } vector<int> ciag; for(int i=0; i<n+1; i++){ if(zliczanie[i]!=0) ciag.push_back(zliczanie[i]); } sort(ciag.begin(), ciag.end()); vector<bool> marked(ciag.size(), false); int wyn=0; int k=0; for(int i=ciag.size()-1; i>=0; i--){ if(marked[i]) break; for(; ciag[i]>ciag[k]; k++){ ciag[i]-=ciag[k]; marked[k]=true; } ciag[k]-=ciag[i]-1; marked[i]=true; wyn++; } cout<<wyn; return 0; } |
English