ll pre[maxn], suf[maxn]; boolcheck(int x){ priority_queue<int, vector<int>, greater<int>> q; priority_queue<int> Q; pre[x] = suf[n - x + 1] = 0; for (int i = 1; i <= x; ++i) q.push(a[i].x), pre[x] += a[i].x; for (int i = x + 1; i <= n; ++i) if (a[i].x > q.top()) { pre[i] = pre[i - 1] - q.top() + a[i].x; q.pop(); q.push(a[i].x); } else pre[i] = pre[i - 1]; for (int i = n - x + 1; i <= n; ++i) Q.push(a[i].y), suf[n - x + 1] += a[i].y; for (int i = n - x; i; --i) if (a[i].y < Q.top()) { suf[i] = suf[i + 1] - Q.top() + a[i].y; Q.pop(); Q.push(a[i].y); } else suf[i] = suf[i + 1]; for (int i = x; i <= n - x; ++i) if (pre[i] >= suf[i + 1]) return1; return0; } intmain(){ ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i].x; for (int i = 1; i <= n; ++i) cin >> a[i].y; sort(a + 1, a + n + 1); int l = 1, r = n / 2, mid, ans = 0; while (l <= r) { mid = l + r >> 1; if (check(mid)) ans = mid, l = mid + 1; else r = mid - 1; } cout << ans << "\n"; return0; }