#include <bits/stdc++.h> using namespace std; #ifdef DEBUG auto&operator<<(auto &o, pair<auto, auto> p) {o << "(" << p.first << ", " << p.second << ")"; return o;} auto operator<<(auto &o, auto x)->decltype(x.end(), o) {o<<"{"; for(auto e : x) o<<e<<", "; return o<<"}";} #define debug(X) cerr << "["#X"]: " << X << '\n'; #else #define cerr if(0)cout #define debug(X) ; #endif using ll = long long; #define all(v) (v).begin(), (v).end() #define ssize(x) int(x.size()) #define fi first #define se second #define mp make_pair #define eb emplace_back int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> a(n); vector<int> wyst(n+1); for(int &x : a) {cin >> x; ++wyst[x];} vector<int> b; for(int i = 1; i <= n; ++i) if(wyst[i] > 0) b.eb(wyst[i]); sort(all(b)); debug(b); int r = ssize(b)-1; int res = 0, s = 0; while (r >= 0 && n-s > s-res) { res++; s += b[r--]; } cout << res << '\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 44 | #include <bits/stdc++.h> using namespace std; #ifdef DEBUG auto&operator<<(auto &o, pair<auto, auto> p) {o << "(" << p.first << ", " << p.second << ")"; return o;} auto operator<<(auto &o, auto x)->decltype(x.end(), o) {o<<"{"; for(auto e : x) o<<e<<", "; return o<<"}";} #define debug(X) cerr << "["#X"]: " << X << '\n'; #else #define cerr if(0)cout #define debug(X) ; #endif using ll = long long; #define all(v) (v).begin(), (v).end() #define ssize(x) int(x.size()) #define fi first #define se second #define mp make_pair #define eb emplace_back int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> a(n); vector<int> wyst(n+1); for(int &x : a) {cin >> x; ++wyst[x];} vector<int> b; for(int i = 1; i <= n; ++i) if(wyst[i] > 0) b.eb(wyst[i]); sort(all(b)); debug(b); int r = ssize(b)-1; int res = 0, s = 0; while (r >= 0 && n-s > s-res) { res++; s += b[r--]; } cout << res << '\n'; return 0; } |