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;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int N; cin >> N;
vector<tuple<int, int, int>> v(N, {0,0,0});
for(int i = 0; i < N; i++){
int X; cin >> X;
get<0>(v[i]) += X;
get<1>(v[i]) = X;
}
for(int i = 0; i < N; i++){
int L; cin >> L;
get<0>(v[i]) += L;
get<2>(v[i]) = L;
}
sort(v.begin(), v.end());
multiset<int> hv;
int ans = 0;
int lvl = 0;
for(int i = 0; i < N; i++){
// cout << get<0>(v[i]) << " " << get<1>(v[i]) << " " << get<2>(v[i]) << "\n";
if(lvl <= get<2>(v[i])){
ans++;
lvl += get<1>(v[i]);
hv.insert(get<1>(v[i]));
}else{
int mx = *hv.rbegin();
if(mx <= get<1>(v[i])) continue;
hv.erase(hv.find(mx));
lvl -= mx; ans--;
if(lvl <= get<2>(v[i])){
ans++;
lvl += get<1>(v[i]);
hv.insert(get<1>(v[i]));
}
}
}
cout << ans << "\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... |