This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int N; cin >> N;
vector<pair<int, int>> v(N);
for(int i = 0; i < N; i++) cin >> v[i].second;
for(int i = 0; i < N; i++) cin >> v[i].first;
sort(v.begin(), v.end());
multiset<int> hv;
int margin = 0;
int lvl = 0;
for(pair<int, int>& p : v){
int L = p.first;
int X = p.second;
if(lvl <= L){
margin = max(margin - X, L - lvl);
lvl += X;
hv.insert(X);
}else if(margin >= X){
margin = min(margin - X, L - lvl);
lvl += X;
hv.insert(X);
}else{
int mx = *hv.rbegin();
if(mx > X){
hv.erase(hv.find(mx));
lvl -= mx;
margin += mx;
if(lvl <= L){
margin = max(margin - X, L - lvl);
lvl += X;
hv.insert(X);
}else if(margin >= X){
margin = min(margin - X, L - lvl);
lvl += X;
hv.insert(X);
}
}
}
}
cout << (int)hv.size() << "\n";
}
# | 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... |