#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); int n; cin >> n; vector<int> v; v.resize(n + 1); for (int i = 0; i < n; ++i) { int k; cin >> k; ++v[k]; } ranges::sort(v, ranges::greater()); int i{}, sum{}; while (i < n && sum < n) { sum += 2 * v[i] - 1; ++i; } cout << i << endl; }
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 <iostream> #include <vector> #include <algorithm> using namespace std; int main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); int n; cin >> n; vector<int> v; v.resize(n + 1); for (int i = 0; i < n; ++i) { int k; cin >> k; ++v[k]; } ranges::sort(v, ranges::greater()); int i{}, sum{}; while (i < n && sum < n) { sum += 2 * v[i] - 1; ++i; } cout << i << endl; } |