#include<bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n; cin >> n; vector <ll> v(n+1,0); for(ll i=0;i<n;i++) { ll x; cin>>x; v[x]++; } sort(v.begin(),v.end(), greater<ll>()); ll res=0; ll j=n-1; while(v[j]==0) { j--; } ll i=0; while(i<=j) { ll k=v[i]-1; v[i]=0; i++; res++; while(k>0&&i<=j) { if(v[j]>k) { v[j]-=k; k=0; } else { k-=v[j]; v[j]=0; j--; } } } cout<<res<<"\n"; 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; typedef long long ll; int main() { ll n; cin >> n; vector <ll> v(n+1,0); for(ll i=0;i<n;i++) { ll x; cin>>x; v[x]++; } sort(v.begin(),v.end(), greater<ll>()); ll res=0; ll j=n-1; while(v[j]==0) { j--; } ll i=0; while(i<=j) { ll k=v[i]-1; v[i]=0; i++; res++; while(k>0&&i<=j) { if(v[j]>k) { v[j]-=k; k=0; } else { k-=v[j]; v[j]=0; j--; } } } cout<<res<<"\n"; return 0; } |