This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Challenge: Accepted
#include <iostream>
#include <algorithm>
#include <utility>
#include <set>
#define maxn 20
#define pii pair<int, int>
#define ff first
#define ss second
using namespace std;
set<pii> dp[1<<maxn];
int a[maxn], b[maxn];
int main() {
int n, m;
cin >> n >> m;
for (int i = 0;i < n;i++) cin >> a[i];
for (int j = 0;j < m;j++) cin >> b[j];
dp[0].insert(make_pair(0, 0));
int poss = 0;
for (int i = 1;i < (1<<m);i++) {
for (int j = 0;j < m;j++) {
if (i & (1<<j)) {
for (auto v: dp[i - (1<<j)]) {
if (v.ss + b[j] == a[v.ff]) {
dp[i].insert(make_pair(v.ff + 1, 0));
} else if (v.ss + b[j] < a[v.ff]) {
dp[i].insert(make_pair(v.ff, v.ss + b[j]));
}
}
}
}
for (auto j:dp[i]) {
if (j.ff == n) {
poss = 1;
break;
}
}
}
cout << (poss ? "YES" : "NO") << "\n";
}
# | 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... |