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;
#define ll long long
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define ii pair<ll,ll>
#define F first
#define S second
int main(){
ll n;
cin>>n;
ll a[n],b[n];
f(i,0,n){
cin>>a[i];
}
f(i,0,n){
cin>>b[i];
}
vector<ii>arr;
f(i,0,n){
arr.pb(ii(a[i]+b[i],a[i]));
}
sort(arr.begin(),arr.end());
ll sum = 0;
multiset<ll>ex;
f(i,0,n){
if(sum + arr[i].S <= arr[i].F){
sum += arr[i].S;
ex.insert(arr[i].S);
}
else{
sum += arr[i].S;
ex.insert(arr[i].S);
auto it = ex.rbegin();
sum -= (*it);
ex.erase(ex.find((*it)));
}
}
cout<<ex.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... |