#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
#define MAXN 300002
using namespace std;
int n, t;
unordered_map<int, int> cc;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> t;
cc[t]++;
}
vector<int> v = {0};
for (auto p : cc) {
v.push_back(p.second);
}
sort(v.begin(), v.end(), greater());
for (int i = 1; i <= n; i++) {
int j = 0;
int res = 0;
while (v[j] >= i) {
res += (v[j] / i) * i;
j++;
}
cout << res << " ";
}
cout << "\n";
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 | #include <iostream> #include <algorithm> #include <vector> #include <unordered_map> #define MAXN 300002 using namespace std; int n, t; unordered_map<int, int> cc; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for (int i = 0; i < n; i++) { cin >> t; cc[t]++; } vector<int> v = {0}; for (auto p : cc) { v.push_back(p.second); } sort(v.begin(), v.end(), greater()); for (int i = 1; i <= n; i++) { int j = 0; int res = 0; while (v[j] >= i) { res += (v[j] / i) * i; j++; } cout << res << " "; } cout << "\n"; return 0; } |
English