#include <bits/stdc++.h>
using namespace std;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
array<int,3>arr[n];
for(int i = 0;i<n;i++){
cin >> arr[i][1];
}
for(int i = 0;i<n;i++){
cin >> arr[i][2];
}
//sum,x,l
for(int i = 0;i<n;i++){
arr[i][0]=arr[i][1]+arr[i][2];
}
sort(arr,arr+n);
int ans = 0;
long long sm = 0;
priority_queue<int>pq;
for(int i = 0;i<n;i++){
if(sm>arr[i][2]){
int neg = pq.top();
if(neg>arr[i][1]&&sm-neg<=arr[i][2]){
sm-=neg;
pq.pop();
}
else{
continue;
}
}
sm+=arr[i][1];
pq.push(arr[i][1]);
ans=max(ans,(int)pq.size());
}
cout << ans;
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... |