#include <iostream> #include <map> using namespace std; map <int, int> zlicz; int wyn[300001]; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); int n; cin >> n; int x, mx = 0; for(int i = 0; i < n; i++) { cin >> x; mx = max(mx, x); if (zlicz[x] == 0) { zlicz[x] = 1; } else { zlicz[x]++; } } int m = n; for (int k = 1; k <= n; k++) { if (mx / k * k == 0) { m = k; break; } } for (auto it = zlicz.begin(); it != zlicz.end(); it++) { for (int k = 1; k <= m; k++) { wyn[k] += (it->second / k) * k; if (wyn[k] == 0) { break; } } } for (int i = 1; i <= n; i++) { cout << wyn[i] << " "; } 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 47 48 49 50 51 52 | #include <iostream> #include <map> using namespace std; map <int, int> zlicz; int wyn[300001]; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); int n; cin >> n; int x, mx = 0; for(int i = 0; i < n; i++) { cin >> x; mx = max(mx, x); if (zlicz[x] == 0) { zlicz[x] = 1; } else { zlicz[x]++; } } int m = n; for (int k = 1; k <= n; k++) { if (mx / k * k == 0) { m = k; break; } } for (auto it = zlicz.begin(); it != zlicz.end(); it++) { for (int k = 1; k <= m; k++) { wyn[k] += (it->second / k) * k; if (wyn[k] == 0) { break; } } } for (int i = 1; i <= n; i++) { cout << wyn[i] << " "; } return 0; } |