#include <bits/stdc++.h> //#pragma GCC optimize("O3") //#pragma GCC target("avx,avx2,fma") #define sz(x) int((x).size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() using namespace std; using ll = long long; using ld = long double; // or double, if TL is tight using str = string; using ii = pair<int, int>; using pl = pair<ll, ll>; using vi = vector<int>; using vll = vector<ll>; int main() { cin.tie(0); ios_base::sync_with_stdio(0); int n; cin >> n; vi V(n); map<int, int> Fr; for(int i = 0; i < n; ++i) { cin >> V[i]; ++Fr[V[i]]; } vi A; for(auto [a, nr] : Fr) A.push_back(nr); sort(rall(A)); for(int i = 1; i <= n; ++i) { int re = 0; for(auto it : A) { if(it < i) break; re += it / i; } cout << re * 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 | #include <bits/stdc++.h> //#pragma GCC optimize("O3") //#pragma GCC target("avx,avx2,fma") #define sz(x) int((x).size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() using namespace std; using ll = long long; using ld = long double; // or double, if TL is tight using str = string; using ii = pair<int, int>; using pl = pair<ll, ll>; using vi = vector<int>; using vll = vector<ll>; int main() { cin.tie(0); ios_base::sync_with_stdio(0); int n; cin >> n; vi V(n); map<int, int> Fr; for(int i = 0; i < n; ++i) { cin >> V[i]; ++Fr[V[i]]; } vi A; for(auto [a, nr] : Fr) A.push_back(nr); sort(rall(A)); for(int i = 1; i <= n; ++i) { int re = 0; for(auto it : A) { if(it < i) break; re += it / i; } cout << re * i << " "; } return 0; } |