#include <algorithm>
#include <iostream>
#include <unordered_map>
#include <vector>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
unordered_map<int, int> liczby;
int num;
cin >> num;
int wszystkie = num;
while (num--) {
int n;
cin >> n;
if (liczby.find(n) != liczby.end()) {
liczby[n]++;
} else {
liczby.insert({n, 1});
}
}
vector<int> v;
v.reserve(liczby.size());
// cout << liczby.size();
for (auto a : liczby) {
v.push_back(a.second);
}
sort(v.begin(), v.end());
reverse(v.begin(), v.end());
int result = 0;
int miejsca = 0;
for (auto a : v) {
wszystkie -= a;
miejsca += a - 1;
result++;
if (wszystkie <= miejsca) {
break;
}
}
cout << result << '\n';
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 | #include <algorithm> #include <iostream> #include <unordered_map> #include <vector> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); unordered_map<int, int> liczby; int num; cin >> num; int wszystkie = num; while (num--) { int n; cin >> n; if (liczby.find(n) != liczby.end()) { liczby[n]++; } else { liczby.insert({n, 1}); } } vector<int> v; v.reserve(liczby.size()); // cout << liczby.size(); for (auto a : liczby) { v.push_back(a.second); } sort(v.begin(), v.end()); reverse(v.begin(), v.end()); int result = 0; int miejsca = 0; for (auto a : v) { wszystkie -= a; miejsca += a - 1; result++; if (wszystkie <= miejsca) { break; } } cout << result << '\n'; return 0; } |
English