#include <iostream>
#include <unordered_map>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n;
cin >> n;
unordered_map<int, int> counts;
vector<int> countsList;
for (int i = 0; i < n; ++i) {
int num;
cin >> num;
counts[num]++;
}
for (auto &count : counts) {
countsList.push_back(count.second);
}
sort(countsList.begin(), countsList.end(), greater());
int size = 0;
int i = 0;
while (size < n) {
int num = countsList[i];
size += 2 * num - 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 26 27 28 29 30 31 32 33 34 35 36 37 38 | #include <iostream> #include <unordered_map> #include <vector> #include <algorithm> using namespace std; int main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); int n; cin >> n; unordered_map<int, int> counts; vector<int> countsList; for (int i = 0; i < n; ++i) { int num; cin >> num; counts[num]++; } for (auto &count : counts) { countsList.push_back(count.second); } sort(countsList.begin(), countsList.end(), greater()); int size = 0; int i = 0; while (size < n) { int num = countsList[i]; size += 2 * num - 1; i++; } cout << i << endl; } |
English