#include "bits/stdc++.h"
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n,m;
cin>>n>>m;
vector<int> salary(n),note(m);
for(int i=0;i<n;i++){
cin>>salary[i];
}
for(int j=0;j<m;j++){
cin>>note[j];
}
vector<int> left((1<<m),-1);
vector<int> covered((1<<m),-1);
left[0]=0;
covered[0]=0;
for(int i=0;i<(1<<m);i++){
for(int j=0;j<m;j++){
if((i&(1<<j))==0) continue;
int prev=i^(1<<j);
if(covered[prev]==-1) continue;
int amt=note[j];
int curr_salary=salary[covered[prev]];
int pre=left[prev];
if(amt+pre<curr_salary){
covered[i]=covered[prev];
left[i]=amt+pre;
}
else if(amt+pre==curr_salary){
covered[i]=covered[prev]+1;
left[i]=0;
}
}
if(covered[i]==n){
cout<<"YES"<<endl;
return 0;
}
}
cout<<"NO"<<endl;
return 0;
}
# | 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... |