#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i = a; i < b;++i)
#define pb emplace_back
using namespace std;
int main(){
cin.tie(0);
ios_base::sync_with_stdio(0);
int n;
cin>>n;
vector<int> cnt(n + 1,0),V;
FOR(i,0,n){
int x;
cin>>x;
++cnt[x];
}
FOR(i,1,n + 1){
if(cnt[i] != 0){
V.pb(cnt[i]);
}
}
sort(V.begin(),V.end(),greater());
int w = 0;
FOR(i,0,n){
w+=V[i] - 1 + V[i];
if(w >= n){
cout<<i + 1;
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 | #include <bits/stdc++.h> #define FOR(i,a,b) for(int i = a; i < b;++i) #define pb emplace_back using namespace std; int main(){ cin.tie(0); ios_base::sync_with_stdio(0); int n; cin>>n; vector<int> cnt(n + 1,0),V; FOR(i,0,n){ int x; cin>>x; ++cnt[x]; } FOR(i,1,n + 1){ if(cnt[i] != 0){ V.pb(cnt[i]); } } sort(V.begin(),V.end(),greater()); int w = 0; FOR(i,0,n){ w+=V[i] - 1 + V[i]; if(w >= n){ cout<<i + 1; return 0; } } } |
English