#include <bits/stdc++.h>
#define pb emplace_back
#define FOR(i,a,b) for(int i = a; i < b;++i)
using namespace std;
int main(){
cin.tie(0);
ios_base::sync_with_stdio(0);
int n;
cin>>n;
vector<int> V,V1;
map<int,int> mapa;
FOR(i,0,n){
int x;
cin>>x;
++mapa[x];
V1.pb(x);
}
FOR(i,0,V1.size()){
if(mapa[V1[i]] != 0){
V.pb(mapa[V1[i]]);
mapa[V1[i]] = 0;
}
}
sort(V.begin(),V.end(),greater());
int x = V[0];
FOR(i,1,n + 1){
int suma = 0;
while(!V.empty() && V[V.size() - 1] < i){
V.pop_back();
}
FOR(j,0,V.size()){
suma+=(V[j] / i) * i;
}
cout<<suma <<" ";
}
}
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 | #include <bits/stdc++.h> #define pb emplace_back #define FOR(i,a,b) for(int i = a; i < b;++i) using namespace std; int main(){ cin.tie(0); ios_base::sync_with_stdio(0); int n; cin>>n; vector<int> V,V1; map<int,int> mapa; FOR(i,0,n){ int x; cin>>x; ++mapa[x]; V1.pb(x); } FOR(i,0,V1.size()){ if(mapa[V1[i]] != 0){ V.pb(mapa[V1[i]]); mapa[V1[i]] = 0; } } sort(V.begin(),V.end(),greater()); int x = V[0]; FOR(i,1,n + 1){ int suma = 0; while(!V.empty() && V[V.size() - 1] < i){ V.pop_back(); } FOR(j,0,V.size()){ suma+=(V[j] / i) * i; } cout<<suma <<" "; } } |
English