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;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n, m; cin >> n >> m;
vector<int> a(n), b(m);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
partial_sum(a.begin(), a.end(), a.begin());
for (int i = 0; i < m; ++i) {
cin >> b[i];
}
vector<int> dp(1 << m, 0);
for (int mask = 1; mask < (1 << m); ++mask) {
int sum = 0;
for (int i = 0; i < m; ++i) {
if (mask >> i & 1) {
sum += b[i];
}
}
for (int i = 0; i < m; ++i) {
if (mask >> i & 1) {
int j = mask ^ (1 << i);
dp[mask] = max(dp[mask], dp[j] + (dp[j] ^ n && sum == a[dp[j]]));
}
}
}
cout << (dp.back() == n ? "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... |