#include <bits/stdc++.h>
using namespace std;
int main(){
int n, helper, sum, result;
int* helperArr;
map<int,int> M;
cin >> n;
for(int i = 0; i < n; ++i){
cin>>helper;
M[helper]++;
}
helperArr = new int[M.size()];
int it = 0;
for(auto i = M.begin(); i != M.end(); ++i){
helperArr[it] = i->second;
++it;
}
sort(helperArr, helperArr + M.size());
sum = 0;
result = 0;
for(int i = M.size() - 1; i >= 0; --i){
++result;
sum += helperArr[i] - 1;
n -= helperArr[i];
if(n <= sum){
break;
}
}
cout<<result<<'\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 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | #include <bits/stdc++.h> using namespace std; int main(){ int n, helper, sum, result; int* helperArr; map<int,int> M; cin >> n; for(int i = 0; i < n; ++i){ cin>>helper; M[helper]++; } helperArr = new int[M.size()]; int it = 0; for(auto i = M.begin(); i != M.end(); ++i){ helperArr[it] = i->second; ++it; } sort(helperArr, helperArr + M.size()); sum = 0; result = 0; for(int i = M.size() - 1; i >= 0; --i){ ++result; sum += helperArr[i] - 1; n -= helperArr[i]; if(n <= sum){ break; } } cout<<result<<'\n'; return 0; } |
English