#include <iostream> #include <vector> #include <map> #include <algorithm> int main() { int n; std::cin >> n; std::vector<int> arr; int num; for (int i = 0; i < n; i++) { std::cin >> num; arr.push_back(num); } std::map<int, int> ord_nums; for (int i : arr) { ord_nums[i]++; } std::vector<int> values; for (auto m : ord_nums) { values.push_back(m.second); } std::sort(values.begin(), values.end(), std::greater<int>()); int res = 1; int i = 0; int j = values.size() - 1; while (i < j) { int s = values[j]; while (values[i] > s) { j--; s += values[j]; } i++; if (i <= j) res++; } std::cout << res; 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 <vector> #include <map> #include <algorithm> int main() { int n; std::cin >> n; std::vector<int> arr; int num; for (int i = 0; i < n; i++) { std::cin >> num; arr.push_back(num); } std::map<int, int> ord_nums; for (int i : arr) { ord_nums[i]++; } std::vector<int> values; for (auto m : ord_nums) { values.push_back(m.second); } std::sort(values.begin(), values.end(), std::greater<int>()); int res = 1; int i = 0; int j = values.size() - 1; while (i < j) { int s = values[j]; while (values[i] > s) { j--; s += values[j]; } i++; if (i <= j) res++; } std::cout << res; return 0; } |