#include <algorithm> #include <iostream> #include <unordered_map> #include <vector> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; unordered_map<int, int> freq; for (int i = 0; i < n; ++i) { int ai; cin >> ai; ++freq[ai]; } vector<int> a; a.reserve(size(freq)); for (auto elem : freq) { a.push_back(elem.second); } ranges::sort(a, ranges::greater()); for (int i = 1; i <= n; ++i) { int sum{}; for (int j = 0; j < size(a) && a[j] >= i; ++j) { sum += a[j] - a[j] % i; } cout << sum << ' '; } cout << endl; }
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 | #include <algorithm> #include <iostream> #include <unordered_map> #include <vector> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; unordered_map<int, int> freq; for (int i = 0; i < n; ++i) { int ai; cin >> ai; ++freq[ai]; } vector<int> a; a.reserve(size(freq)); for (auto elem : freq) { a.push_back(elem.second); } ranges::sort(a, ranges::greater()); for (int i = 1; i <= n; ++i) { int sum{}; for (int j = 0; j < size(a) && a[j] >= i; ++j) { sum += a[j] - a[j] % i; } cout << sum << ' '; } cout << endl; } |