#include<bits/stdc++.h>
using namespace std;
int n,x,w[300009],s;
int main()
{
cin>>n;
int tab[n];
for(int i=0; i<n; i++)
{
cin>>tab[i];
}
sort(tab,tab+n);
w[0]=1;
for(int i=1; i<n; i++)
{
if(tab[i-1]==tab[i])
{
w[x]++;
}
else
{
x++;
w[x]++;
}
}
sort(w,w+(x+1));
for(int i=1; i<=n; i++)
{
for(int j=x; j>=0; j--)
{
if(w[j]>=i)
{
s+=(i*(w[j]/i));
}
else break;
}
cout<<s<<' ';
s=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 | #include<bits/stdc++.h> using namespace std; int n,x,w[300009],s; int main() { cin>>n; int tab[n]; for(int i=0; i<n; i++) { cin>>tab[i]; } sort(tab,tab+n); w[0]=1; for(int i=1; i<n; i++) { if(tab[i-1]==tab[i]) { w[x]++; } else { x++; w[x]++; } } sort(w,w+(x+1)); for(int i=1; i<=n; i++) { for(int j=x; j>=0; j--) { if(w[j]>=i) { s+=(i*(w[j]/i)); } else break; } cout<<s<<' '; s=0; } } |
English