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;
#define endl '\n'
#define debug(x) cerr << #x << " == " << (x) << '\n';
#define all(x) begin(x), end(x)
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int N, M;
cin >> N >> M;
vector<int> a(N), b(M);
for (auto& x : a) cin >> x;
for (auto& x : b) cin >> x;
vector<int> sum(1 << M);
vector<vector<int>> E(N);
for (int j = 0; j < M; ++j) sum[1 << j] = b[j];
for (int mask = 1; mask < (1 << M); ++mask) {
int lsb = mask & -mask;
sum[mask] = sum[mask ^ lsb] + sum[lsb];
for (int i = 0; i < N; ++i) {
if (sum[mask] == a[i]) E[i].push_back(mask);
}
}
vector<bool> dp(1 << M, false), dpnxt(1 << M, false);
dp[0] = true;
for (int i = 0; i < N; ++i) {
for (int mask = 0; mask < (1 << M); ++mask) {
if (not dp[mask]) continue;
for (auto add : E[i]) {
if (mask & add) continue;
dpnxt[mask | add] = true;
}
}
fill(all(dp), false), swap(dp, dpnxt);
}
string ans = count(all(dp), true) ? "YES" : "NO";
cout << ans << endl;
exit(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... |