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::sync_with_stdio(false); cin.tie(nullptr);
int n, m;
cin >> n >> m;
vector<int> a(n + 1), p(n + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i];
p[i] = p[i - 1] + a[i];
}
vector<int> b(m);
for (int i = 0; i < m; i++) cin >> b[i];
vector<int> sum(1<<m);
for (int j = 0; j < 1<<m; j++) {
for (int i = 0; i < m; i++) {
if ((j>>i) & 1) sum[j] += b[i];
}
}
vector<vector<bool>> dp(n + 1, vector<bool>(1<<m));
for (int j = 0; j < 1<<m; j++) {
dp[0][j] = true;
}
for (int i = 1; i <= n; i++) {
for (int j = 0; j < 1<<m; j++) {
if (sum[j] == p[i] && dp[i - 1][j]) dp[i][j] = true;
}
for (int j = 0; j < 1<<m; j++) {
for (int k = 0; k < m; k++) {
if (((j>>k) & 1) && dp[i][j - (1<<k)]) dp[i][j] = true;
}
}
}
cout << (count(dp[n].begin(), dp[n].end(), true) ? "YES" : "NO");
}
# | 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... |