#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
map<int, int> city_to_count;
vector<int> counts; // liczby znaczków z miast, docelowo sortowana
int n; cin >> n;
for (int i = 0; i < n; ++i) {
int ai; cin >> ai;
city_to_count[ai] += 1;
}
// for (auto pair: city_to_count) {
// cout << pair.first << ' ' << pair.second << endl;
// }
for (auto pair: city_to_count) {
counts.push_back(pair.second);
}
sort(counts.begin(), counts.end());
// for (int c: counts) {
// cout << c << " ";
// }
// cout << endl;
for (int k = 1; k <= n; ++k) {
int sum = 0;
for (auto it = counts.rbegin(); it != counts.rend(); ++it) {
int v = *it / k;
if (v == 0)
break;
else
sum += v * k;
}
cout << sum << " ";
}
cout << endl;
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 | #include <iostream> #include <vector> #include <map> #include <algorithm> using namespace std; int main() { ios_base::sync_with_stdio(0); map<int, int> city_to_count; vector<int> counts; // liczby znaczków z miast, docelowo sortowana int n; cin >> n; for (int i = 0; i < n; ++i) { int ai; cin >> ai; city_to_count[ai] += 1; } // for (auto pair: city_to_count) { // cout << pair.first << ' ' << pair.second << endl; // } for (auto pair: city_to_count) { counts.push_back(pair.second); } sort(counts.begin(), counts.end()); // for (int c: counts) { // cout << c << " "; // } // cout << endl; for (int k = 1; k <= n; ++k) { int sum = 0; for (auto it = counts.rbegin(); it != counts.rend(); ++it) { int v = *it / k; if (v == 0) break; else sum += v * k; } cout << sum << " "; } cout << endl; return 0; } |
English