#include <iostream>
#include <unordered_map>
#include <algorithm>
using namespace std;
int wyst[300005];
unordered_map <int, int> nr;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
int act_nr = 0;
for(int i = 1; i <= n; i++)
{
int a;
cin >> a;
if(nr.find(a) == nr.end())
{
nr[a] = act_nr;
act_nr++;
}
wyst[nr[a]]++;
}
sort(wyst, wyst + n);
for(int i = 1; i <= n; i++)
{
int sum = 0;
for(int j = n - 1; j >= 0 && wyst[j] >= i; j--)
{
sum += ((wyst[j] / i) * i);
}
cout << sum << ' ';
}
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 <unordered_map> #include <algorithm> using namespace std; int wyst[300005]; unordered_map <int, int> nr; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; int act_nr = 0; for(int i = 1; i <= n; i++) { int a; cin >> a; if(nr.find(a) == nr.end()) { nr[a] = act_nr; act_nr++; } wyst[nr[a]]++; } sort(wyst, wyst + n); for(int i = 1; i <= n; i++) { int sum = 0; for(int j = n - 1; j >= 0 && wyst[j] >= i; j--) { sum += ((wyst[j] / i) * i); } cout << sum << ' '; } return 0; } |
English