#include <iostream> #include <algorithm> // std::sort using namespace std; int counter[500000]; int main() { ios_base::sync_with_stdio(0); int n, a; cin >> n; for (int i = 0; i < n; ++i) { cin >> a; counter[a]++; } sort(counter + 1, counter + n + 1, greater<int>()); int covered_num = 0; int i = 0; while (covered_num < n) { i++; covered_num += 2 * counter[i] - 1; } cout << i; }
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 | #include <iostream> #include <algorithm> // std::sort using namespace std; int counter[500000]; int main() { ios_base::sync_with_stdio(0); int n, a; cin >> n; for (int i = 0; i < n; ++i) { cin >> a; counter[a]++; } sort(counter + 1, counter + n + 1, greater<int>()); int covered_num = 0; int i = 0; while (covered_num < n) { i++; covered_num += 2 * counter[i] - 1; } cout << i; } |