#include <iostream> #include <vector> #include <map> using namespace std; int main() { int n; cin >> n; map<int, int> stamp_counts; for (int i = 0; i < n; i++) { int stamp; cin >> stamp; stamp_counts[stamp]++; } vector<int> results(n, 0); for (int k = 1; k <= n; k++) { int total_stamps = 0; for (auto it = stamp_counts.begin(); it != stamp_counts.end();) { total_stamps += (*it).second / k; if ((*it).second < k) { stamp_counts.erase(it++); } else { it++; } } results[k - 1] = total_stamps * k; if (total_stamps == 0) { break; } } for (int result : results) { cout << result << " "; } cout << endl; 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 | #include <iostream> #include <vector> #include <map> using namespace std; int main() { int n; cin >> n; map<int, int> stamp_counts; for (int i = 0; i < n; i++) { int stamp; cin >> stamp; stamp_counts[stamp]++; } vector<int> results(n, 0); for (int k = 1; k <= n; k++) { int total_stamps = 0; for (auto it = stamp_counts.begin(); it != stamp_counts.end();) { total_stamps += (*it).second / k; if ((*it).second < k) { stamp_counts.erase(it++); } else { it++; } } results[k - 1] = total_stamps * k; if (total_stamps == 0) { break; } } for (int result : results) { cout << result << " "; } cout << endl; return 0; } |