#include <iostream> #include <vector> #include <algorithm> int main() { int n, x; std::cin >> n; std::vector<long> input; for (int i = 0; i < n; i++) { std::cin >> x; input.push_back(x); } std::sort(input.begin(), input.end()); std::vector<int> amount; int counter = 0; int val = input[0]; for (int i = 0; i < n; i++) { if (input[i] == val) { counter++; } else { amount.push_back(counter); val = input[i]; counter = 1; } } amount.push_back(counter); std::sort(amount.begin(), amount.end()); int m = amount.size(); int beg = 0, res = 0; for (int i = 1; i <= n; i++) { for (int j = beg; j < m; j++) { if (i > amount[j]) beg++; res += amount[j] - (amount[j] % i); } std::cout << res << " "; res = 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 | #include <iostream> #include <vector> #include <algorithm> int main() { int n, x; std::cin >> n; std::vector<long> input; for (int i = 0; i < n; i++) { std::cin >> x; input.push_back(x); } std::sort(input.begin(), input.end()); std::vector<int> amount; int counter = 0; int val = input[0]; for (int i = 0; i < n; i++) { if (input[i] == val) { counter++; } else { amount.push_back(counter); val = input[i]; counter = 1; } } amount.push_back(counter); std::sort(amount.begin(), amount.end()); int m = amount.size(); int beg = 0, res = 0; for (int i = 1; i <= n; i++) { for (int j = beg; j < m; j++) { if (i > amount[j]) beg++; res += amount[j] - (amount[j] % i); } std::cout << res << " "; res = 0; } } |