#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][2];
}
for(int i = 0;i<n;i++){
cin >> arr[i][1];
}
//sum,l,x
for(int i = 0;i<n;i++){
arr[i][0]=arr[i][1]+arr[i][2];
}
sort(arr,arr+n);
int ans = 0;
vector<pair<int,priority_queue<int>>>lis;
lis.push_back({arr[0][2],priority_queue<int>()});
lis[0].second.push(arr[0][2]);
for(int i = 1;i<n;i++){
bool skip=0;
if(lis.back().first<=arr[i][1]){
lis.push_back(lis.back());
lis.back().first+=arr[i][2];
lis.back().second.push(arr[i][2]);
skip=1;
}
for(int j = 0;j<lis.size()-skip;j++){
lis[j].first+=arr[i][2];
lis[j].second.push(arr[i][2]);
lis[j].first-=lis[j].second.top();
lis[j].second.pop();
}
}
cout << lis.size();
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... |