#include <iostream> #include <algorithm> #include <vector> #include <queue> #include <unordered_map> #include <assert.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/trie_policy.hpp> //using namespace __gnu_pbds using namespace std; template<class A, class B> ostream& operator<<(ostream& o, const pair<A, B>& p) { return o << '(' << p.first << ", " << p.second << ')'; } template<class A, class B, class C> ostream& operator<<(ostream& o, const tuple<A, B, C>& t) { return o << '(' << get<0>(t) << ", " << get<1>(t) << ", " << get<2>(t) << ')'; } template<class T> auto operator<<(ostream& o, const T& x) -> decltype(x.end(), o) { o << '{'; int i = 0; for (const auto& e : x) { o << (", ") + 2 * !i++ << e; } return o << '}'; } auto operator<<(ostream& o, const string& s) -> decltype(o) { for (const auto& e : s) { o << e; } return o; } //#define DEBUG #ifdef DEBUG #define fastio() #define debug(x...) cerr << "[" #x "]: ", [](auto... $) {((cerr << $ << "; "), ...); }(x), cerr << '\n' #define asrt(x) if (!(x)) { cerr << "Assertion failed: " << #x << " in line " << __LINE__ << endl; exit(1); } #else #define fastio() ios_base::sync_with_stdio(0); cin.tie(0); #define debug(...) #define asrt(x) #endif #define pii pair<int,int> #define inf 2'000'000'000 #define llinf 8'000'000'000'000'000'000 #define mod 998'244'353 #define mod7 1'000'000'007 #define mod9 1'000'000'009 #define eps 0.00000000001 #define all(x) x.begin(),x.end() #define rev(x) x.rbegin(),x.rend() #define decrease(x) x,vector<x>,greater<x> #define maxn 500'000 typedef long long ll; typedef long double ld; vector <int> v; int bsort[maxn + 5]; void solve() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { int x; cin >> x; bsort[x]++; } for (int i = 1; i <= n; i++) if (bsort[i] > 0) v.push_back(bsort[i]); sort(all(v), greater<int>()); debug(v); for (int i = 0; i < v.size(); i++) { n -= 2 * v[i] - 1; if (n <= 0) { printf("%d\n", i + 1); exit(0); } } } signed main() { if (maxn + 0 == 0) cerr << "WARNING - maxn is undefined\n"; if (maxn + 0 <= 100) cerr << "warning - maxn might be too low\n"; int t = 1; //cin >> t; while (t--) solve(); }
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <unordered_map> #include <assert.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/trie_policy.hpp> //using namespace __gnu_pbds using namespace std; template<class A, class B> ostream& operator<<(ostream& o, const pair<A, B>& p) { return o << '(' << p.first << ", " << p.second << ')'; } template<class A, class B, class C> ostream& operator<<(ostream& o, const tuple<A, B, C>& t) { return o << '(' << get<0>(t) << ", " << get<1>(t) << ", " << get<2>(t) << ')'; } template<class T> auto operator<<(ostream& o, const T& x) -> decltype(x.end(), o) { o << '{'; int i = 0; for (const auto& e : x) { o << (", ") + 2 * !i++ << e; } return o << '}'; } auto operator<<(ostream& o, const string& s) -> decltype(o) { for (const auto& e : s) { o << e; } return o; } //#define DEBUG #ifdef DEBUG #define fastio() #define debug(x...) cerr << "[" #x "]: ", [](auto... $) {((cerr << $ << "; "), ...); }(x), cerr << '\n' #define asrt(x) if (!(x)) { cerr << "Assertion failed: " << #x << " in line " << __LINE__ << endl; exit(1); } #else #define fastio() ios_base::sync_with_stdio(0); cin.tie(0); #define debug(...) #define asrt(x) #endif #define pii pair<int,int> #define inf 2'000'000'000 #define llinf 8'000'000'000'000'000'000 #define mod 998'244'353 #define mod7 1'000'000'007 #define mod9 1'000'000'009 #define eps 0.00000000001 #define all(x) x.begin(),x.end() #define rev(x) x.rbegin(),x.rend() #define decrease(x) x,vector<x>,greater<x> #define maxn 500'000 typedef long long ll; typedef long double ld; vector <int> v; int bsort[maxn + 5]; void solve() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { int x; cin >> x; bsort[x]++; } for (int i = 1; i <= n; i++) if (bsort[i] > 0) v.push_back(bsort[i]); sort(all(v), greater<int>()); debug(v); for (int i = 0; i < v.size(); i++) { n -= 2 * v[i] - 1; if (n <= 0) { printf("%d\n", i + 1); exit(0); } } } signed main() { if (maxn + 0 == 0) cerr << "WARNING - maxn is undefined\n"; if (maxn + 0 <= 100) cerr << "warning - maxn might be too low\n"; int t = 1; //cin >> t; while (t--) solve(); } |