#include<bits/stdc++.h> using namespace std; int n, x; int counter[1000005]; vector<int> vec; int main(){ cin >> n; for(int i = 1 ; i <= n ; i++) { cin >> x; counter[x]++; } int suma = n; for(int i = 1 ; i <= n ; i++){ if (counter[i] > 0) { vec.push_back(counter[i]); } } sort(vec.begin(), vec.end()); int ile_mozemy_dodac = 0; for(int i = vec.size() - 1 ; i >= 0 ; i--){ suma -= vec[i]; ile_mozemy_dodac += (vec[i] - 1); if(suma <= ile_mozemy_dodac){ cout << vec.size() - i << endl; 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<bits/stdc++.h> using namespace std; int n, x; int counter[1000005]; vector<int> vec; int main(){ cin >> n; for(int i = 1 ; i <= n ; i++) { cin >> x; counter[x]++; } int suma = n; for(int i = 1 ; i <= n ; i++){ if (counter[i] > 0) { vec.push_back(counter[i]); } } sort(vec.begin(), vec.end()); int ile_mozemy_dodac = 0; for(int i = vec.size() - 1 ; i >= 0 ; i--){ suma -= vec[i]; ile_mozemy_dodac += (vec[i] - 1); if(suma <= ile_mozemy_dodac){ cout << vec.size() - i << endl; return 0; } } } |