#include <iostream>
#include <unordered_set>
#include <vector>
using namespace std;
constexpr int MAXN = 20, MAXM = 20;
int n, m, a[MAXN + 1], b[MAXM];
unordered_set<int> dp[MAXN + 1];
vector<int> configs[1001];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
for (int i = 0; i < m; ++i) {
cin >> b[i];
}
for (int s = 0; s < (1 << m); ++s) {
int val = 0;
for (int i = 0; i < m; ++i) {
if (s & (1 << i)) {
val += b[i];
}
}
if (val <= 1000) {
configs[val].push_back(s);
}
}
dp[0] = {0};
for (int i = 0; i < n; ++i) {
for (auto s : dp[i]) {
for (auto j : configs[a[i + 1]]) {
if (s & j) {
continue;
}
dp[i + 1].insert(s | j);
}
}
}
cout << (!dp[n].empty() ? "YES" : "NO");
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... |