#include <bits/stdc++.h>
using namespace std;
#define int long long
#define N 500005
int tc = 1, n, a[N], m, b[N], dp[21][(1<<20)], sm[N];
int32_t main() {
ios::sync_with_stdio(0);cin.tie(0);
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++) {
dp[0][i] = 1;
for(int j = 0; j < m; j++) {
if((i >> j) & 1) {
sm[i] += b[j];
}
}
}
for(int i = 0; i < n; i++) {
for(int j = 0; j < (1 << m); j++) {
for(int k = j; k > 0; k--) {
if(((j & k) == k) && (sm[k] == a[i])) {
dp[i + 1][j] |= dp[i][j ^ k];
}
}
}
}
bool ok = 0;
for(int i = 0; i < (1 << m); i++) {
if(dp[n][i]) {
ok = 1;
break;
}
}
cout <<(ok == 1? "YES\n" : "NO\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... |