#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define ertunt return
int main() {
ll n, m;
cin >> n >> m;
ll a[n], b[m];
for (ll i = 0; i < n; i++) cin >> a[i];
for (ll i = 0; i < m; i++) cin >> b[i];
vector<ll> v[n + 5];
for (ll i = 1; i < (1 << m); i++) {
ll cur = 0;
for (ll j = 0; j < m; j++) {
if (i & (1 << j)) {
cur += b[j];
}
}
for (ll j = 0; j < n; j++) {
if (a[j] == cur) v[j].pb(i);
}
}
ll dp[n + 2][(1 << m) + 4];
memset(dp, 0, sizeof(dp));
for (auto x : v[0]) dp[0][x] = 1;
for (ll i = 1; i < n; i++) {
for (ll j = 0; j < (1 << m); j++) {
if (dp[i - 1][j] == 0) continue;
for (auto x : v[i]) {
if ((x & j) == 0) dp[i][x | j] = 1;
}
}
}
for (ll i = 0; i < (1 << m); i++) {
if (dp[n - 1][i] == 1) {
cout << "YES";
ertunt 0;
}
}
cout << "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... |