Untitled
unknown
c_cpp
8 months ago
1.0 kB
8
Indexable
#include <bits/stdc++.h>
using namespace std;
void MO3TAZOLEQ() {
#ifdef MOATAZOLEQ
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
#define ll long long
void solve() {
map<int, int> front, back, same;
int n;
cin >> n;
set<int> s;
for (int i = 0; i < n; ++i) {
int x, y;
cin >> x >> y;
front[x]++;
back[y]++;
s.insert(x);
s.insert(y);
if (x == y) {
same[x]++;
}
}
int ans = 1e9;
for (auto cand: s) {
int cnt = front[cand] + back[cand] - same[cand];
if (cnt * 2 >= n) {
int need = (n + 1) / 2 - front[cand];
if (need <= 0) {
ans = 0;
break;
}
ans = min(ans, need);
}
}
cout << (ans == 1e9 ? -1 : ans);
}
int main() {
MO3TAZOLEQ();
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
Editor is loading...
Leave a Comment