#include <bits/stdc++.h>
using namespace std;
const int q=5*1e5+1;
int zlicz[q];
vector <int> v;
int main(){
int n; cin>>n;
int maxi=0;
for(int i=1; i<=n; i++){
int x; cin>>x;
zlicz[x]++;
maxi=max(maxi,x);
}
for(int i=1; i<=maxi; i++)
if(zlicz[i])
v.push_back(-zlicz[i]);
sort(v.begin(),v.end());
// for(int i=0; i<v.size(); i++)
// cout<<v[i]<<" ";
int licz=n,res=0,wsk=0;
while(licz>0){
licz+=2*v[wsk]+1;
wsk++;
res++;
}
cout<<res<<endl;
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 | #include <bits/stdc++.h> using namespace std; const int q=5*1e5+1; int zlicz[q]; vector <int> v; int main(){ int n; cin>>n; int maxi=0; for(int i=1; i<=n; i++){ int x; cin>>x; zlicz[x]++; maxi=max(maxi,x); } for(int i=1; i<=maxi; i++) if(zlicz[i]) v.push_back(-zlicz[i]); sort(v.begin(),v.end()); // for(int i=0; i<v.size(); i++) // cout<<v[i]<<" "; int licz=n,res=0,wsk=0; while(licz>0){ licz+=2*v[wsk]+1; wsk++; res++; } cout<<res<<endl; return 0; } |
English