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;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
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];
sort(a, a + n);
vector<int> masks[n];
for(int mask = 0; mask < (1 << m); mask++) {
int sum = 0;
for(int j = 0; j < m; j++) if((1 << j) & mask) sum += b[j];
for(int i = 0; i < n; i++) if(sum == a[i]) masks[i].push_back(mask);
}
bool dp[n][1 << m];
for(int i = 0; i < n; i++) for(int j = 0; j < (1 << m); j++) dp[i][j] = false;
for(int i : masks[0]) dp[0][i] = true;
for(int i = 1; i < n; i++) {
for(int mask = 0; mask < (1 << m); mask++) {
for(int mask2 : masks[i]) {
if((mask | mask2) == mask && dp[i - 1][mask ^ mask2]) {
dp[i][mask] = true;
}
}
}
}
for(int i = 0; i < (1 << m); i++) {
if(dp[n - 1][i]) {
cout << "YES";
return 0;
}
}
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... |