#include <iostream> #include <algorithm> using namespace std; const int SIZE = 300000; int main(int argc, char const *argv[]) { int n; long long a[SIZE]; int b[SIZE]; int res[SIZE] = {}; cin >> n; for (int i=0; i<n; i++) { cin >> a[i]; } sort(a, a + n); int size = 0; long long last = a[0]; b[size] = 1; for (int i=1; i<n; i++) { if (a[i] == last) { b[size]++; } else { size++; last = a[i]; b[size] = 1; } } size++; sort(b, b + size); int from = 0; int z = 0; for (int i=1; i<=n; i++) { while (b[from] < i && from < size) { from++; } z = 0; for (int j=from; j<size; j++) { z += b[j] / i; } cout << z*i << " "; } cout << endl; 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 53 | #include <iostream> #include <algorithm> using namespace std; const int SIZE = 300000; int main(int argc, char const *argv[]) { int n; long long a[SIZE]; int b[SIZE]; int res[SIZE] = {}; cin >> n; for (int i=0; i<n; i++) { cin >> a[i]; } sort(a, a + n); int size = 0; long long last = a[0]; b[size] = 1; for (int i=1; i<n; i++) { if (a[i] == last) { b[size]++; } else { size++; last = a[i]; b[size] = 1; } } size++; sort(b, b + size); int from = 0; int z = 0; for (int i=1; i<=n; i++) { while (b[from] < i && from < size) { from++; } z = 0; for (int j=from; j<size; j++) { z += b[j] / i; } cout << z*i << " "; } cout << endl; return 0; } |