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(){
int n,m;
cin>>n>>m;
int b[m];
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=0;i<m;i++){
cin>>b[i];
}
vector<int>covered(1<<m,-1);
vector<int>left(1<<m,-1);
left[0]=0;
covered[0]=0;
for(int mask=1;mask<(1<<m);mask++){
for(int j=0;j<m;j++){
if((1<<j)&mask && covered[mask^(1<<j)]!=-1){
int msk=mask^(1<<j);
int cur=a[covered[msk]];
int amt=left[msk]+b[j];
if(amt<cur){
covered[mask]=covered[msk];
left[mask]=amt;
}
else if(amt==cur){
covered[mask]=covered[msk]+1;
left[mask]=0;
}
}
}
if(covered[mask]==n){
cout<<"YES"<<endl;
return 0;
}
}
cout<<"NO"<<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... |