#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
int wyst[500000];
int main()
{
cin.sync_with_stdio(0); cin.tie(0);
int n;
scanf("%d", &n);
for(int i=0; i<n; i++) wyst[i]=0;
for(int i=0; i<n; i++){
int j;
scanf("%d", &j);
wyst[j-1]++;
}
sort(wyst, wyst+n);
//for(int i=0; i<n; i++) cout << wyst[i] << endl;
int suma=0;
int wyn=0;
while(suma<n){
suma+=2*wyst[n-1-wyn]-1;
wyn++;
}
cout << wyn;
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 <iostream> #include <fstream> #include <algorithm> using namespace std; int wyst[500000]; int main() { cin.sync_with_stdio(0); cin.tie(0); int n; scanf("%d", &n); for(int i=0; i<n; i++) wyst[i]=0; for(int i=0; i<n; i++){ int j; scanf("%d", &j); wyst[j-1]++; } sort(wyst, wyst+n); //for(int i=0; i<n; i++) cout << wyst[i] << endl; int suma=0; int wyn=0; while(suma<n){ suma+=2*wyst[n-1-wyn]-1; wyn++; } cout << wyn; return 0; } |
English