#include <bits/stdc++.h> // LID
using namespace std;
typedef long long ll;
const int MAXN = 5e5+7;
int aps[MAXN];
bool cmp(const int &a, const int &b) {
return a > b;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, a;
cin >> n;
for(int i = 0; i < n; i++){
cin >> a;
aps[a]++;
}
vector<int> t;
for(int i = 0; i < MAXN; i++){
if(aps[i]>0) t.push_back(aps[i]);
}
sort(t.begin(), t.end(), cmp);
ll sum = 0;
int ans = 0;
for(auto e : t){
ans++;
sum+=(ll)2*e-1;
if(sum>=n) break;
}
cout << ans << '\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 | #include <bits/stdc++.h> // LID using namespace std; typedef long long ll; const int MAXN = 5e5+7; int aps[MAXN]; bool cmp(const int &a, const int &b) { return a > b; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n, a; cin >> n; for(int i = 0; i < n; i++){ cin >> a; aps[a]++; } vector<int> t; for(int i = 0; i < MAXN; i++){ if(aps[i]>0) t.push_back(aps[i]); } sort(t.begin(), t.end(), cmp); ll sum = 0; int ans = 0; for(auto e : t){ ans++; sum+=(ll)2*e-1; if(sum>=n) break; } cout << ans << '\n'; return 0; } |
English