# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
961548 | doducanh | Bank (IZhO14_bank) | C++14 | 102 ms | 8560 KiB |
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 leftovers[(1<<20)+7];
int people_cover[(1<<20)+7];
int a[25],b[25];
int n,m;
main()
{
cin>>n>>m;
for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<m;i++)cin>>b[i];
for(int mask=1;mask<(1<<m);mask++)people_cover[mask]=-1;
people_cover[0]=0;
leftovers[0]=0;
for(int mask=1;mask<(1<<m);mask++){
for(int i=0;i<=m;i++){
if((mask>>i)&1){
int prev=(mask^(1<<i));
if(people_cover[prev]==-1)continue;
int amt=leftovers[prev]+b[i];
if(amt<a[people_cover[prev]]){
leftovers[mask]=amt;
people_cover[mask]=people_cover[prev];
}
else if(amt==a[people_cover[prev]]){
leftovers[mask]=0;
people_cover[mask]=people_cover[prev]+1;
}
}
}
if(people_cover[mask]==n){
cout<<"YES";
return 0;
}
}
cout<<"NO";
return 0;
}
Compilation message (stderr)
# | 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... |