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 int long long
const int N = 21;
int n, m, pre[N], b[N], dp[(1 << N)], sum;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> pre[i];
pre[i] += pre[i - 1];
}
for (int i = 0; i < m; i++) {
cin >> b[i];
}
for (int mask = 1; mask < (1 << m); mask++) {
sum = 0;
for (int i = 0; i < m; i++) {
if ((mask & (1 << i))) sum += b[i];
}
for (int i = 0; i < m; i++) {
if ((mask & (1 << i))) {
int x = dp[mask ^ (1 << i)];
dp[mask] = max (dp[mask], x + (pre[x] == sum));
}
}
}
if (dp[(1 << m) - 1] == n) cout << "YES";
else 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... |