#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int d[300009];
int t[300009];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> d[i];
}
sort(d, d + n);
int id = 0;
t[id] = 1;
for (int i = 1; i < n; i++) {
if (d[i] != d[i - 1]) {
id++;
}
t[id]++;
}
id++;
sort(t, t + id);
reverse(t, t + id);
for (int i = 1; i <= n; i++) {
int sum = 0;
for (int j = 0; j < id; j++) {
sum += (t[j] / i) * i;
if (t[j] / i == 0) {
id = j;
break;
}
}
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 40 | #include <bits/stdc++.h> using namespace std; typedef long long LL; int d[300009]; int t[300009]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; for (int i = 0; i < n; i++) { cin >> d[i]; } sort(d, d + n); int id = 0; t[id] = 1; for (int i = 1; i < n; i++) { if (d[i] != d[i - 1]) { id++; } t[id]++; } id++; sort(t, t + id); reverse(t, t + id); for (int i = 1; i <= n; i++) { int sum = 0; for (int j = 0; j < id; j++) { sum += (t[j] / i) * i; if (t[j] / i == 0) { id = j; break; } } cout << sum << " "; } return 0; } |
English