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>
#define int long long
using namespace std;
const int sm = 20;
int a[sm], b[sm];
int dp[(1ll << sm)];
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i ++) {
cin >> a[i];
}
for (int i = 1; i < n; i ++) {
a[i] += a[i - 1];
}
for (int i = 0; i < m; i ++) {
cin >> b[i];
}
for (int i = 0; i < (1ll << m); i ++) {
int mx = -1, sm = 0;
for (int j = 0; j < m; j ++) {
if (i & (1ll << j)) {
mx = max(mx, dp[i ^ (1ll << j)]);
sm += b[j];
}
}
dp[i] = mx + (sm == a[mx + 1]);
if (n - 1 == dp[i]) {
cout << "YES";
return 0;
}
}
cout << "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... |