#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); vector<int> stamps; for (int i = 0; i < n; ++i) { int a; scanf("%d", &a); stamps.push_back(a); } sort(stamps.begin(), stamps.end()); vector<int> counts = {1}; for (int i = 1; i < n; ++i) { if (stamps[i] == stamps[i-1]) { counts.back()++; } else { counts.push_back(1); } } sort(counts.begin(), counts.end()); for (int k = 1; k <= n; ++k) { int sum = 0; for (int i = counts.size() - 1; i >= 0; --i) { if (counts[i] < k) { break; } sum += counts[i] / k * k; } printf("%d ", sum); } }
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 | #include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); vector<int> stamps; for (int i = 0; i < n; ++i) { int a; scanf("%d", &a); stamps.push_back(a); } sort(stamps.begin(), stamps.end()); vector<int> counts = {1}; for (int i = 1; i < n; ++i) { if (stamps[i] == stamps[i-1]) { counts.back()++; } else { counts.push_back(1); } } sort(counts.begin(), counts.end()); for (int k = 1; k <= n; ++k) { int sum = 0; for (int i = counts.size() - 1; i >= 0; --i) { if (counts[i] < k) { break; } sum += counts[i] / k * k; } printf("%d ", sum); } } |