#include <algorithm>
#include <functional>
#include <iostream>
#include <unordered_map>
#include <vector>
int main(int argc, char** argv)
{
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
int n{0};
std::cin >> n;
std::unordered_map<int, int> m{};
int nn{n};
while(nn--) {
int a{0};
std::cin >> a;
m[a] += 1;
}
std::vector<int> stamps{};
auto max{0};
for (auto el : m) {
auto [k,v] = el;
//std::cout << k << " " << v << "\n";
stamps.push_back(v);
if (v > max) {
max = v;
}
}
std::vector<int> res(n);
std::sort(stamps.begin(), stamps.end(), std::greater<int>());
res[0] = n;
// for(auto el: stamps) {
// std::cout << el << " ";
// }
// std::cout << "\n";
for(int i=2; i<=max; i++) {
int sum{0};
for(auto el: stamps) {
if(el < i) break;
sum += (el / i) * i;
}
res[i-1] = sum;
}
for (int i=0; i<res.size()-1; i++) {
std::cout << res[i] << " ";
}
std::cout << res[res.size()-1] << "\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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | #include <algorithm> #include <functional> #include <iostream> #include <unordered_map> #include <vector> int main(int argc, char** argv) { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); int n{0}; std::cin >> n; std::unordered_map<int, int> m{}; int nn{n}; while(nn--) { int a{0}; std::cin >> a; m[a] += 1; } std::vector<int> stamps{}; auto max{0}; for (auto el : m) { auto [k,v] = el; //std::cout << k << " " << v << "\n"; stamps.push_back(v); if (v > max) { max = v; } } std::vector<int> res(n); std::sort(stamps.begin(), stamps.end(), std::greater<int>()); res[0] = n; // for(auto el: stamps) { // std::cout << el << " "; // } // std::cout << "\n"; for(int i=2; i<=max; i++) { int sum{0}; for(auto el: stamps) { if(el < i) break; sum += (el / i) * i; } res[i-1] = sum; } for (int i=0; i<res.size()-1; i++) { std::cout << res[i] << " "; } std::cout << res[res.size()-1] << "\n"; return 0; } |
English