#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];
}
vector<int> new_dp((1LL << m), 0);
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);
}
for(auto u : inc[a[0]]) {
new_dp[u] = 1;
}
for(int i = 1; i < n; i++) {
vector<int> dp((1LL << m), 0);
for(auto u : inc[a[i]]) {
for(int j = 0; j < (1LL << m); j++) {
if((j & u)) {
continue;
}
dp[u ^ j] |= new_dp[j];
}
}
new_dp = dp;
}
int ok = 0;
for(int i = 0; i < (1LL << m); i++) {
ok |= new_dp[i];
}
cout << (ok? "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... |