#include <bits/stdc++.h> using namespace std; int n; vector<int> Read() { vector<int> a; scanf("%d", &n); a.resize(n); for (int i = 0; i < n; i++) scanf("%d", &a[i]); ranges::sort(a); vector<int> v; int last = -1; int count = 0; for (int i : a) { if (i != last && count > 0) { v.push_back(count); count = 0; } count++; last = i; } v.push_back(count); ranges::sort(v); ranges::reverse(v); return v; } int main() { vector<int> x = Read(); for (int i = 1; i <= n; i++) { while (!x.empty() && x.back() < i) x.pop_back(); int s = 0; for (int c : x) s += (c / i) * i; if (i > 1) putchar(' '); printf("%d", s); } putchar('\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 42 43 44 45 46 47 48 49 50 | #include <bits/stdc++.h> using namespace std; int n; vector<int> Read() { vector<int> a; scanf("%d", &n); a.resize(n); for (int i = 0; i < n; i++) scanf("%d", &a[i]); ranges::sort(a); vector<int> v; int last = -1; int count = 0; for (int i : a) { if (i != last && count > 0) { v.push_back(count); count = 0; } count++; last = i; } v.push_back(count); ranges::sort(v); ranges::reverse(v); return v; } int main() { vector<int> x = Read(); for (int i = 1; i <= n; i++) { while (!x.empty() && x.back() < i) x.pop_back(); int s = 0; for (int c : x) s += (c / i) * i; if (i > 1) putchar(' '); printf("%d", s); } putchar('\n'); return 0; } |