#include <bits/stdc++.h>
using namespace std;
int t[500100];
vector<int> v;
int main()
{
ios_base::sync_with_stdio(0);
int a, x;
int s=0, i=1;
cin>>a;
for(int i=0; i<a; i++)
{
cin>>x;
t[x]++;
}
for(int i=0; i<=a; i++)
{
if(t[i]!=0) v.push_back(t[i]);
}
sort(v.begin(), v.end(), greater<int>());
for(auto g: v)
{
s+=2*g-1;
if(s>=a)
{
cout<<i;
return 0;
}
i++;
}
cout<<i;
}
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 | #include <bits/stdc++.h> using namespace std; int t[500100]; vector<int> v; int main() { ios_base::sync_with_stdio(0); int a, x; int s=0, i=1; cin>>a; for(int i=0; i<a; i++) { cin>>x; t[x]++; } for(int i=0; i<=a; i++) { if(t[i]!=0) v.push_back(t[i]); } sort(v.begin(), v.end(), greater<int>()); for(auto g: v) { s+=2*g-1; if(s>=a) { cout<<i; return 0; } i++; } cout<<i; } |
English