#include <iostream> #include <vector> #include <algorithm> using namespace std; const int N = 300007; const int A = 1000000007; int tab[1000]; vector <int> kubelki; int main() { int n, a, maxval = 0; cin >> n; for(int i = 0; i < n; i++) { cin >> a; if(a > maxval) maxval = a; tab[a]++; } for(int i = 0; i <= maxval; i++) { if(tab[i]) { kubelki.push_back(tab[i]); tab[i] = 0; } } sort(kubelki.begin(), kubelki.end()); for(int i = kubelki.size() - 1; i >= 0; i--) { int maksymalny = kubelki[i]; int count = 1; while(kubelki[i - 1] == maksymalny && i > 0) { count++; i--; } for(int j = maksymalny; j > 0; j--) { tab[j] += (maksymalny / j) * count * j; } } for(int i = 1; i <= n; i++) cout << tab[i] << " "; }
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 | #include <iostream> #include <vector> #include <algorithm> using namespace std; const int N = 300007; const int A = 1000000007; int tab[1000]; vector <int> kubelki; int main() { int n, a, maxval = 0; cin >> n; for(int i = 0; i < n; i++) { cin >> a; if(a > maxval) maxval = a; tab[a]++; } for(int i = 0; i <= maxval; i++) { if(tab[i]) { kubelki.push_back(tab[i]); tab[i] = 0; } } sort(kubelki.begin(), kubelki.end()); for(int i = kubelki.size() - 1; i >= 0; i--) { int maksymalny = kubelki[i]; int count = 1; while(kubelki[i - 1] == maksymalny && i > 0) { count++; i--; } for(int j = maksymalny; j > 0; j--) { tab[j] += (maksymalny / j) * count * j; } } for(int i = 1; i <= n; i++) cout << tab[i] << " "; } |