#include<bits/stdc++.h> using namespace std; const int lim = 300'003; unordered_map < int, int > mapa; vector < int > v; int tab[lim]; int wyn[lim]; int main(){ std::ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int a, cnt = 1; for(int i = 0; i < n; i++){ cin >> a; if(mapa.find(a) == mapa.end()){ mapa[a] = cnt; cnt ++; } tab[mapa[a]]++; } for(int i = 1; i < cnt; i++){ v.push_back(tab[i]); } sort(v.begin(), v.end(), greater < int >()); for(int i: v){ for(int j = i; j > 0; j--){ wyn[j] += (i / j) * j; } } for(int i = 1; i <= n; i++){ cout << (wyn[i]) << " "; } }
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 | #include<bits/stdc++.h> using namespace std; const int lim = 300'003; unordered_map < int, int > mapa; vector < int > v; int tab[lim]; int wyn[lim]; int main(){ std::ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int a, cnt = 1; for(int i = 0; i < n; i++){ cin >> a; if(mapa.find(a) == mapa.end()){ mapa[a] = cnt; cnt ++; } tab[mapa[a]]++; } for(int i = 1; i < cnt; i++){ v.push_back(tab[i]); } sort(v.begin(), v.end(), greater < int >()); for(int i: v){ for(int j = i; j > 0; j--){ wyn[j] += (i / j) * j; } } for(int i = 1; i <= n; i++){ cout << (wyn[i]) << " "; } } |