#include <stdio.h>
#include <stdlib.h>
int N;
int tab[300001];
int compare(const void * a, const void * b)
{
return *(int*)b - *(int*)a;
}
int main(){
int x;
int j,s;
scanf ("%d",&N);
for(int i=0;i<N;i++)
{
scanf("%d",&x);
tab[i]=x;
}
qsort(tab, N, sizeof(int), compare);
j=0;
s=1;
for(int i=1;i<N;i++)
{
if(tab[i]!=tab[i-1])
{
tab[j]=s;
s=1;
j++;
}
else
{
s++;
}
}
tab[j]=s;
for(int i=j+1;i<N;i++)tab[i]=0;
qsort(tab, N, sizeof(int), compare);
for(int i=1;i<=N;i++)
{
j=0;s=0;
while(tab[j]>=i)
{
s+=(tab[j]/i)*i;
j++;
}
printf("%d ",s);
}
printf("\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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | #include <stdio.h> #include <stdlib.h> int N; int tab[300001]; int compare(const void * a, const void * b) { return *(int*)b - *(int*)a; } int main(){ int x; int j,s; scanf ("%d",&N); for(int i=0;i<N;i++) { scanf("%d",&x); tab[i]=x; } qsort(tab, N, sizeof(int), compare); j=0; s=1; for(int i=1;i<N;i++) { if(tab[i]!=tab[i-1]) { tab[j]=s; s=1; j++; } else { s++; } } tab[j]=s; for(int i=j+1;i<N;i++)tab[i]=0; qsort(tab, N, sizeof(int), compare); for(int i=1;i<=N;i++) { j=0;s=0; while(tab[j]>=i) { s+=(tab[j]/i)*i; j++; } printf("%d ",s); } printf("\n"); return 0; } |
English