#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cout << fixed << setprecision(10);
int n;
cin >> n;
vector<int> a(n);
for (int &ai : a)
cin >> ai;
map<int, int> count;
for (int ai : a)
count[ai]++;
vector<int> q;
for (auto &[x, c] : count)
q.push_back(c);
sort(q.begin(), q.end());
for (int x = 1; x <= n; x++) {
int ans = 0;
for (int i = q.size() - 1; i >= 0; i--) {
if (q[i] < x)
break;
ans += q[i] / x * x;
}
cout << ans << " ";
}
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 38 39 40 41 | #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout << fixed << setprecision(10); int n; cin >> n; vector<int> a(n); for (int &ai : a) cin >> ai; map<int, int> count; for (int ai : a) count[ai]++; vector<int> q; for (auto &[x, c] : count) q.push_back(c); sort(q.begin(), q.end()); for (int x = 1; x <= n; x++) { int ans = 0; for (int i = q.size() - 1; i >= 0; i--) { if (q[i] < x) break; ans += q[i] / x * x; } cout << ans << " "; } cout << "\n"; return 0; } |
English