This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 20;
int n, m, a[N], b[N];
pair<int, int> dp[(1 << N)];
int main() {
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < m; i++) cin >> b[i];
dp[0] = {0, 0};
bool pos = false;
for (int s = 0; s < (1 << m); s++) {
if (dp[s].first == n) {
pos = true;
break;
}
for (int j = 0; j < m; j++) {
if (s & (1 << j)) continue;
pair<int, int> new_state;
if (a[dp[s].first] == dp[s].second + b[j]) {
new_state = {dp[s].first + 1, 0};
} else new_state = {dp[s].first, dp[s].second + b[j]};
dp[s | (1 << j)] = max(dp[s | (1 << j)], new_state);
}
}
cout << (pos ? "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... |