#include <iostream>
#include <vector>
using namespace std;
constexpr int MAXN = 20, MAXM = 20;
int n, m, a[MAXN + 1], b[MAXM];
bool dp[MAXN + 1][1 << MAXM];
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] = true;
for (int i = 1; i <= n; ++i) {
for (int s = 0; s < (1 << m); ++s) {
for (auto j : configs[a[i]]) {
if ((s & j) != j) {
continue;
}
if (dp[i - 1][s ^ j]) {
dp[i][s] = true;
break;
}
}
if (i == n && dp[i][s]) {
cout << "YES";
return 0;
}
}
cout << '\n';
}
cout << "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... |