#include <iostream> #include <map> #include <vector> #include <algorithm> #include <functional> using namespace std; int n; map<int, int> nums; int main() { cin.tie(0)->sync_with_stdio(0); cin>>n; for(int i=0; i<n; i++){ int val; cin>>val; nums[val]++; } vector<int> vals; vals.reserve(nums.size()); for(auto [k, v] : nums){ vals.push_back(v); } int k = nums.size(); sort(vals.begin(), vals.end(), greater<int>()); for(int i=1; i<=n; i++){ int res = 0; for(int j=0; j<k; j++){ if(vals[j] / i == 0){ break; } res += vals[j] / i; } cout<<res*i<<' '; } cout<<'\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 37 38 39 | #include <iostream> #include <map> #include <vector> #include <algorithm> #include <functional> using namespace std; int n; map<int, int> nums; int main() { cin.tie(0)->sync_with_stdio(0); cin>>n; for(int i=0; i<n; i++){ int val; cin>>val; nums[val]++; } vector<int> vals; vals.reserve(nums.size()); for(auto [k, v] : nums){ vals.push_back(v); } int k = nums.size(); sort(vals.begin(), vals.end(), greater<int>()); for(int i=1; i<=n; i++){ int res = 0; for(int j=0; j<k; j++){ if(vals[j] / i == 0){ break; } res += vals[j] / i; } cout<<res*i<<' '; } cout<<'\n'; return 0; } |