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;
int n, m;
int dp[(1 << 20)], w[(1 << 20)], b[20];
int sum_a[30], a[30];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; i++) {
cin >> a[i];
sum_a[i] = a[i] + sum_a[i - 1];
}
for(int i = 0; i < m; i++)
cin >> b[i];
for(int msk = 0; msk < (1 << m); msk++) {
for(int i = 0; i < m; i++) {
if(msk >> i & 1)
w[msk] += b[i];
}
}
for(int msk = 1; msk < (1 << m); msk++) {
for(int i = 0; i < m; i++) {
if(~msk >> i & 1) continue;
int msk1 = msk ^ (1 << i);
dp[msk] = max(dp[msk], dp[msk1] + (w[msk1] - sum_a[dp[msk1]] + b[i] == a[dp[msk1] + 1]));
}
}
cout << (dp[(1 << m) - 1] == n ? "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... |