#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin>>n; map<int, int> ilosc_znaczkow; int znaczek; for (int i=0; i<n; ++i) { cin>>znaczek; ilosc_znaczkow[znaczek]++; } int solve[n+1] = {0}; for (map<int, int>::iterator it=ilosc_znaczkow.begin(); it!=ilosc_znaczkow.end(); ++it) { for (int i=1; i<=it->second; ++i) { solve[i] += (it->second)/i; } } for (int i=1; i<=n; ++i) { cout<<solve[i]*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 | #include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin>>n; map<int, int> ilosc_znaczkow; int znaczek; for (int i=0; i<n; ++i) { cin>>znaczek; ilosc_znaczkow[znaczek]++; } int solve[n+1] = {0}; for (map<int, int>::iterator it=ilosc_znaczkow.begin(); it!=ilosc_znaczkow.end(); ++it) { for (int i=1; i<=it->second; ++i) { solve[i] += (it->second)/i; } } for (int i=1; i<=n; ++i) { cout<<solve[i]*i<<" "; } } |