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;
using ll = long long;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> a(n), b(m);
for(int i = 0; i < n; i++) {
cin >> a[i];
}
for(int i = 0; i < m; i++) {
cin >> b[i];
}
vector<bool> dp(1 << m), prev(1 << m);
dp[0] = true;
for(int i = 0; i < n; i++) {
swap(dp, prev);
fill(dp.begin(), dp.end(), false);
bool exists = false;
for(int mask = 0; mask < (1 << m); mask++) {
int curr = 0;
for(int j = 0; j < m; j++) {
if(1 & (mask >> j)) curr += b[j];
}
if(curr != a[i]) continue;
exists = true;
for(int mask1 = mask; mask1 < (1 << m); ++mask1 |= mask) {
if(prev[mask1^mask]) {
dp[mask] = true;
break;
}
}
}
if(!exists) {
cout << "NO";
return 0;
}
}
bool ans = false;
for(int i = 0; i < (1 << m); i++) {
if(dp[i]) {
ans = true;
}
}
cout << (ans ? "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... |