#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
#define int long long
#define ll long long
#define vc vector<char>
#define vi vector<int>
#define vb vector<bool>
#define pi pair<int, int>
#define ppi pair<pair<int, int>, int>
#define pip pair<int, pair<int, int>>
#define multi multiset<int>
#define multp multiset<pi>
#define endl '\n'
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
const int MOD = 1e9 + 7;
const int MAXN = 2e5+5;
const int S = 350;
void solve() {
int n;
cin >> n;
vi X(n), L(n);
for (int &x : X) cin >> x;
for (int &x : L) cin >> x;
vector<pi> arr;
for (int i = 0; i < n; i++) {
arr.push_back({X[i], L[i]});
}
sort(arr.begin(), arr.end(), [](pi p1, pi p2) {
return (p1.first + p1.second) < (p2.first + p2.second);
});
int res = 0, sum = 0;
priority_queue<pi> pq;
for (int i = 0; i < n; i++) {
int x, l;
tie(x, l) = arr[i];
if (sum <= l) { res++; sum += x; pq.push({x, i}); continue; }
pi p = pq.top();
if (p.first <= x) continue;
sum -= p.first;
pq.pop();
sum += x;
pq.push({x, i});
}
cout << res << endl;
}
/*
*/
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
bool test = 0;
int t;
if (!test) t = 1;
else cin >> t;
while (t--) {
solve();
}
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |