#include <iostream> #include <algorithm> #include <vector> #include <cassert> #include <chrono> using namespace std; int main() { ios::sync_with_stdio(false); std::cin.tie(NULL); int n; std::cin >> n; std::vector<int> miasta; for (int i = 0; i < n; ++i) { int miasto; std::cin >> miasto; miasta.push_back(miasto); } std::sort(miasta.begin(), miasta.end()); std::vector<int> counts; int count = 1; for (int i = 1; i < miasta.size(); ++i) { if (miasta[i] == miasta[i - 1]) count++; else { counts.push_back(count); count = 1; } } counts.push_back(count); std::sort(counts.begin(), counts.end()); int poczatek = 0; for (int k = 1; k <= n; ++k) { while (poczatek < counts.size() && counts[poczatek] < k) { poczatek++; } int suma = 0; for (int i = poczatek; i < counts.size(); ++i) { suma += counts[i] - (counts[i] % k); } std::cout << suma << " "; } 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 | #include <iostream> #include <algorithm> #include <vector> #include <cassert> #include <chrono> using namespace std; int main() { ios::sync_with_stdio(false); std::cin.tie(NULL); int n; std::cin >> n; std::vector<int> miasta; for (int i = 0; i < n; ++i) { int miasto; std::cin >> miasto; miasta.push_back(miasto); } std::sort(miasta.begin(), miasta.end()); std::vector<int> counts; int count = 1; for (int i = 1; i < miasta.size(); ++i) { if (miasta[i] == miasta[i - 1]) count++; else { counts.push_back(count); count = 1; } } counts.push_back(count); std::sort(counts.begin(), counts.end()); int poczatek = 0; for (int k = 1; k <= n; ++k) { while (poczatek < counts.size() && counts[poczatek] < k) { poczatek++; } int suma = 0; for (int i = poczatek; i < counts.size(); ++i) { suma += counts[i] - (counts[i] % k); } std::cout << suma << " "; } return 0; } |