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 endl "\n"
#define all(aa) aa.begin(), aa.end()
int main(){
ll n;
cin>>n;
vector<ll> a(n), b(n), x(n);
for(auto &e:a) cin>>e;
for(auto &e:b) cin>>e;
iota(all(x), 0);
sort(all(x), [&](ll l, ll r){
return (b[l]-a[r]<min({b[l], b[r], b[r]-a[l]}));
});
int ans=0;
for(int mask=0; mask<(1<<n); mask++){
bool f=1;
ll cur=0;
for(ll i=0; i<n; i++){
if(mask&(1<<i)){
if(cur<=b[i]){
cur+=a[i];
}
else{
f=0;
break;
}
}
}
if(f) ans=max(ans, __builtin_popcount(mask));
}
cout<<ans<<endl;
}
# | 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... |