#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MX = 1e5 + 5;
vector<int> inc[MX];
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> a(n);
vector<int> b(m);
for(int i = 0; i < n; i++) {
cin >> a[i];
}
for(int i = 0; i < m; i++) {
cin >> b[i];
}
for(int bitmask = 0; bitmask < (1LL << m); bitmask++) {
int sum = 0;
for(int j = 0; j < m; j++) {
if(bitmask & (1LL << j)) {
sum += b[j];
}
}
inc[sum].push_back(bitmask);
}
vector<int> prev;
prev.push_back(0);
for(int i = 0; i < n; i++) {
vector<int> qn;
vector<int> was((1LL << m), 0);
for(auto x : inc[a[i]]) {
for(auto y : prev) {
if((x & y) || was[x ^ y]) {
continue;
}
qn.push_back((x ^ y));
was[x ^ y] = 1;
}
}
prev = qn;
}
cout << (prev.size()? "YES" : "NO");
}
# | 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... |