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 pll pair<ll, ll>
#define pii pair<int, int>
#define fs first
#define sc second
#define pb push_back
void solve() {
int n,m;
cin>>n>>m;
int a[n],b[m];
for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<m;i++)cin>>b[i];
vector<int> ma[20001];
for(int m1=0;m1<(1<<m);m1++){
int s=0;
for(int i=0;i<m;i++){
if(m1&(1<<i))s+=b[i];
}
ma[s].pb(m1);
}
vector<int> v;
v.pb(0);
for(int i=0;i<n;i++){
vector<int> v2;
for(int m1:v){
for(int m2:ma[a[i]]){
if((m1&m2)==0){
v2.pb(m1^m2);
}
}
}
v=v2;
}
if(!v.empty())cout<<"YES";
else cout<<"NO";
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
solve();
}
# | 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... |