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 = 1000;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
bitset<N + 1> dp;
dp[0] = 1;
for (int i = 0; i < m; i++) {
int x;
cin >> x;
for (int i = 0; i < 1000; i++) {
dp |= dp << x;
}
}
vector<bool> f(1 << n);
f[0] = 1;
for (int i = 1; i < (1 << n); i++) {
for (int j = 0; j < n; j++) {
if (i >> j & 1) {
if (dp[a[j]] && f[i ^ (1 << j)]) {
f[i] = 1;
}
}
}
}
cout << (f[(1 << n) - 1] ? "YES\n" : "NO\n");
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... |