#include<bits/stdc++.h>
#define int long long
using namespace std;
int x[500005];
int l[500005];
int badge[500005];
vector<pair<int,int>>v;
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;cin>>n;
for(int i=1;i<=n;i++)cin>>x[i];
for(int i=1;i<=n;i++)cin>>l[i];
for(int i=1;i<=n;i++){
v.push_back({l[i]+x[i],i});
}
for(int i=1;i<=n;i++)badge[i]=5e14+5;
badge[0]=0;
sort(v.begin(),v.end());
for(int i=0;i<v.size();i++){
for(int j=n;j>=0;j--){
if(badge[j]<=l[v[i].second])badge[j+1]=min(badge[j+1],x[v[i].second]+badge[j]);
}
}
for(int i=n;i>=0;i--)if(badge[i]<5e14+5){
cout<<i<<"\n";
break;
}
}
# | 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... |