#include <algorithm> #include <iostream> #include <map> #include <vector> int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); int n; std::cin >> n; std::map<int, int> counters; for (int i = 0; i < n; i++) { int a; std::cin >> a; counters[a]++; } std::vector<int> values; for (auto it = counters.begin(); it != counters.end(); it++) { values.push_back(it->second); } std::sort(values.begin(), values.end()); for (int i = 1; i <= n; i++) { int sum = 0; for (auto it = std::lower_bound(values.begin(), values.end(), i); it != values.end(); ++it) { sum += (*it / i) * i; } std::cout << sum << " "; } std::cout << "\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 | #include <algorithm> #include <iostream> #include <map> #include <vector> int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); int n; std::cin >> n; std::map<int, int> counters; for (int i = 0; i < n; i++) { int a; std::cin >> a; counters[a]++; } std::vector<int> values; for (auto it = counters.begin(); it != counters.end(); it++) { values.push_back(it->second); } std::sort(values.begin(), values.end()); for (int i = 1; i <= n; i++) { int sum = 0; for (auto it = std::lower_bound(values.begin(), values.end(), i); it != values.end(); ++it) { sum += (*it / i) * i; } std::cout << sum << " "; } std::cout << "\n"; return 0; } |