#include <bits/stdc++.h> #define pb push_back using namespace std; constexpr int N = 5e5+7; bool wewsort(int a, int b){ return a > b; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; int ile[n]; fill(ile, ile+n, 0); for(int i = 0; i < n; i++){ int a1; cin >> a1; ile[a1-1]++; } int obsiz = 0; sort(ile, ile+n, wewsort); int j = 0; while(obsiz < n){ obsiz += 2*ile[j]-1; j++; } cout << j; 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 31 32 | #include <bits/stdc++.h> #define pb push_back using namespace std; constexpr int N = 5e5+7; bool wewsort(int a, int b){ return a > b; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; int ile[n]; fill(ile, ile+n, 0); for(int i = 0; i < n; i++){ int a1; cin >> a1; ile[a1-1]++; } int obsiz = 0; sort(ile, ile+n, wewsort); int j = 0; while(obsiz < n){ obsiz += 2*ile[j]-1; j++; } cout << j; return 0; } |