#include<bits/stdc++.h> #define LL long long #define LLL __int128 #define uint unsigned #define ldb long double #define uLL unsigned long long using namespace std; const int N=5e5+5; int n,a[N]; signed main(){ cin.tie(0)->sync_with_stdio(0); cin>>n; for(int i=1;i<=n;++i){int x;cin>>x,++a[x];} sort(a+1,a+n+1); int s=0,p=n; while((n-s)*2+(n-p)>s)s+=a[p--]; cout<<n-p; return 0; } /* */
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include<bits/stdc++.h> #define LL long long #define LLL __int128 #define uint unsigned #define ldb long double #define uLL unsigned long long using namespace std; const int N=5e5+5; int n,a[N]; signed main(){ cin.tie(0)->sync_with_stdio(0); cin>>n; for(int i=1;i<=n;++i){int x;cin>>x,++a[x];} sort(a+1,a+n+1); int s=0,p=n; while((n-s)*2+(n-p)>s)s+=a[p--]; cout<<n-p; return 0; } /* */ |