#include <bits/stdc++.h>
using namespace std;
multiset<pair<int,int>> s;
map<int,int> m;
int main()
{
int n;
cin >> n;
for(int i = 0; i < n; i++)
{
int a; cin >> a;
m[a]++;
}
for(auto& it: m) s.insert(it);
for(int i = 1; i <= n; i++)
{
int wynik = 0;
multiset<pair<int,int>>::iterator it2;
bool czy = false;
for(auto& it: s)
{
if(czy) s.erase(it2);
czy = false;
if(it.second/i != 0) wynik += (it.second/i) * i;
else
{
it2 = s.find(it);
czy = true;
}
}
if(czy) s.erase(it2);
cout << wynik << " ";
}
}
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 | #include <bits/stdc++.h> using namespace std; multiset<pair<int,int>> s; map<int,int> m; int main() { int n; cin >> n; for(int i = 0; i < n; i++) { int a; cin >> a; m[a]++; } for(auto& it: m) s.insert(it); for(int i = 1; i <= n; i++) { int wynik = 0; multiset<pair<int,int>>::iterator it2; bool czy = false; for(auto& it: s) { if(czy) s.erase(it2); czy = false; if(it.second/i != 0) wynik += (it.second/i) * i; else { it2 = s.find(it); czy = true; } } if(czy) s.erase(it2); cout << wynik << " "; } } |
English