#include <vector> #include <iostream> #include <numeric> #include <algorithm> #include <unordered_map> using namespace std; int main() { ios_base::sync_with_stdio(false); int a, n; cin >> n; unordered_map<int, int> counter; for (int i = 0; i < n; i++) { cin >> a; counter[a]++; } vector<int> counts; counts.reserve(counter.size()); for (const auto &item: counter) { counts.push_back(item.second); } sort(counts.begin(), counts.end(), greater<>()); for (int i = 1; i <= n; i++) { int sum = 0; for (const auto &item: counts) { if (item < i) { break; } sum += item - item % i; } cout << sum << " "; } cout << endl; 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 | #include <vector> #include <iostream> #include <numeric> #include <algorithm> #include <unordered_map> using namespace std; int main() { ios_base::sync_with_stdio(false); int a, n; cin >> n; unordered_map<int, int> counter; for (int i = 0; i < n; i++) { cin >> a; counter[a]++; } vector<int> counts; counts.reserve(counter.size()); for (const auto &item: counter) { counts.push_back(item.second); } sort(counts.begin(), counts.end(), greater<>()); for (int i = 1; i <= n; i++) { int sum = 0; for (const auto &item: counts) { if (item < i) { break; } sum += item - item % i; } cout << sum << " "; } cout << endl; return 0; } |