#include <bits/stdc++.h>
using namespace std;
#define MAGICZNE_ZAKLECIE std::ios::sync_with_stdio(0);\
cin.tie(0);\
cout.tie(0);
class cmp {
public:
bool operator() (const int& lhs, const int& rhs) const {
return rhs < lhs;
}
};
int main() {
MAGICZNE_ZAKLECIE;
int n;
cin >> n;
unordered_map<int, int> val_count;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
auto emplace_result = val_count.emplace(a, 1);
if (!emplace_result.second) {
emplace_result.first->second++;
}
}
map<int, int, cmp> count_count;
for (auto i : val_count) {
auto emplace_result = count_count.emplace(i.second, 1);
if (!emplace_result.second) {
emplace_result.first->second++;
}
}
int result = 0;
int sum = 0;
for (auto i : count_count) {
for (int j = 0; j < i.second; j++) {
result++;
sum += i.first;
if (sum * 2 >= n) {
cout << result;
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 44 45 46 47 48 49 50 51 52 53 | #include <bits/stdc++.h> using namespace std; #define MAGICZNE_ZAKLECIE std::ios::sync_with_stdio(0);\ cin.tie(0);\ cout.tie(0); class cmp { public: bool operator() (const int& lhs, const int& rhs) const { return rhs < lhs; } }; int main() { MAGICZNE_ZAKLECIE; int n; cin >> n; unordered_map<int, int> val_count; for (int i = 0; i < n; i++) { int a; cin >> a; auto emplace_result = val_count.emplace(a, 1); if (!emplace_result.second) { emplace_result.first->second++; } } map<int, int, cmp> count_count; for (auto i : val_count) { auto emplace_result = count_count.emplace(i.second, 1); if (!emplace_result.second) { emplace_result.first->second++; } } int result = 0; int sum = 0; for (auto i : count_count) { for (int j = 0; j < i.second; j++) { result++; sum += i.first; if (sum * 2 >= n) { cout << result; return 0; } } } } |
English