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>
#define MAXN 21
using namespace std;
int a[MAXN], b[MAXN];
bool possible[MAXN][1 << MAXN];
vector<int> combos[MAXN * 1000];
int N, M;
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];
for(int mask = 0; mask < (1 << M); mask++) {
int sum = 0;
for(int i = 0; i < M; i++) {
if(mask & (1 << i)) sum += b[i];
}
combos[sum].push_back(mask);
}
possible[0][0] = true;
for(int i = 0; i < N; i++) {
for(int mask = 1; mask < (1 << M); mask++) {
for(int combo : combos[a[i]]) {
if((combo & mask) == combo) possible[i+1][mask] |= possible[i][mask - combo];
}
}
}
bool res = false;
for(int i = 0; i < (1 << M); i++) res |= possible[N][i];
if(res) cout << "YES\n";
else cout << "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... |