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;
vector<int> v[1000005];
int a[20],b[20];
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n,m;
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 i=0;i<(1<<m);i++){
int uang=0;
for(int j=0;j<m;j++){
if((1<<j) & i)uang+=b[j];
}
v[uang].push_back(i);
}
if(v[a[0]].empty()){
cout << "NO\n";
return 0;
}
vector<int> valid;
valid.push_back((1<<m)-1);
for(int i=0;i<n;i++){
if(v[a[i]].empty()){
cout << "NO\n";
return 0;
}
vector<int> bisa;
for(auto isi : valid){
for(auto isi2 : v[a[i]]){
if((isi&isi2)==isi2)bisa.push_back(isi-isi2);
}
}
// sort(bisa.begin(),bisa.end());
// bisa.erase(unique(bisa.begin(),bisa.end()),bisa.end());
valid=bisa;
if(valid.empty())break;
}
if(valid.empty())cout << "NO\n";
else cout << "YES\n";
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... |