#include <iostream> #include <vector> #include <algorithm> using namespace std; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n,k,i1=500000,i2=500000,s=0,m; cin >> n; vector<int>ciag(500000); for(int i=0;i<n;++i){ cin >> k; ciag[k-1]++; } sort(ciag.begin(),ciag.end()); for(int i=0;i<500000;++i){ if(ciag[i]!=0){ i1=i; break; } } while(i1<i2){ s++; m=ciag[i2-1]; i2--; while(m>0){ if(ciag[i1]<=m){ m-=ciag[i1]; i1++; } else{ ciag[i1]-=m; m=0; } } } cout << s; 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 | #include <iostream> #include <vector> #include <algorithm> using namespace std; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n,k,i1=500000,i2=500000,s=0,m; cin >> n; vector<int>ciag(500000); for(int i=0;i<n;++i){ cin >> k; ciag[k-1]++; } sort(ciag.begin(),ciag.end()); for(int i=0;i<500000;++i){ if(ciag[i]!=0){ i1=i; break; } } while(i1<i2){ s++; m=ciag[i2-1]; i2--; while(m>0){ if(ciag[i1]<=m){ m-=ciag[i1]; i1++; } else{ ciag[i1]-=m; m=0; } } } cout << s; return 0; } |