#include <cstdio> #include <vector> #include <algorithm> using namespace std; int main() { int n; scanf("%d", &n); vector<int> a(n), b; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } sort(a.begin(), a.end()); a.push_back(-1); int c = 1; for (int i = 0; i < n; i++) { if (a[i] != a[i+1]) { b.push_back(c); c = 1; } else { c++; } } sort(b.begin(), b.end()); int pocz = 0; for (int k = 1; k <= n; k++) { while(pocz < b.size() && b[pocz] < k) pocz++; int w = 0; for (int i = pocz; i < b.size(); ++i) { w += b[i] - b[i] % k; } printf("%d ", w); } printf("\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 | #include <cstdio> #include <vector> #include <algorithm> using namespace std; int main() { int n; scanf("%d", &n); vector<int> a(n), b; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } sort(a.begin(), a.end()); a.push_back(-1); int c = 1; for (int i = 0; i < n; i++) { if (a[i] != a[i+1]) { b.push_back(c); c = 1; } else { c++; } } sort(b.begin(), b.end()); int pocz = 0; for (int k = 1; k <= n; k++) { while(pocz < b.size() && b[pocz] < k) pocz++; int w = 0; for (int i = pocz; i < b.size(); ++i) { w += b[i] - b[i] % k; } printf("%d ", w); } printf("\n"); return 0; } |