#include<bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> t(n);
for(int& i : t)
cin >> i;
sort(t.begin(), t.end());
vector<pair<int,int>> cnt;
cnt.push_back({0, t[0]});
for(int i : t) {
if(i != cnt.back().second)
cnt.push_back({0, i});
cnt.back().first++;
}
sort(cnt.begin(), cnt.end(), greater<pair<int,int>>());
int result = 0;
int sum = 0;
for(auto [a, _] : cnt) {
sum += 2*a-1;
result++;
if(sum >= n) 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 | #include<bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> t(n); for(int& i : t) cin >> i; sort(t.begin(), t.end()); vector<pair<int,int>> cnt; cnt.push_back({0, t[0]}); for(int i : t) { if(i != cnt.back().second) cnt.push_back({0, i}); cnt.back().first++; } sort(cnt.begin(), cnt.end(), greater<pair<int,int>>()); int result = 0; int sum = 0; for(auto [a, _] : cnt) { sum += 2*a-1; result++; if(sum >= n) break; } cout << result << "\n"; return 0; } |
English