#include <iostream> #include <algorithm> using namespace std; int n, t[500007] = {}, t2[500007] = {}, score=0, it=0; int main(){ std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); cin>>n; for(int i=0;i<n;i++){ cin>>t[i]; t2[t[i]]--; } sort(t2, t2+n+1); while(n>0){ n += t2[it]*2; n++; score++; it++; } cout<<score<<"\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 | #include <iostream> #include <algorithm> using namespace std; int n, t[500007] = {}, t2[500007] = {}, score=0, it=0; int main(){ std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); cin>>n; for(int i=0;i<n;i++){ cin>>t[i]; t2[t[i]]--; } sort(t2, t2+n+1); while(n>0){ n += t2[it]*2; n++; score++; it++; } cout<<score<<"\n"; return 0; } |