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 main() {
cin.tie(nullptr)->sync_with_stdio(false);
int N, M;
cin >> N >> M;
vector<int> a(N);
for (int &value : a) {
cin >> value;
}
vector<int> b(M);
for (int &value : b) {
cin >> value;
}
vector<int> pref(N + 1);
for (int i = 0; i < N; i++) {
pref[i + 1] = pref[i] + a[i];
}
vector<int> dp(1 << M), sum(1 << M);
dp[0] = 1;
for (int mask = 1; mask < (1 << M); mask++) {
for (int i = 0; i < M; i++) {
if ((mask >> i) & 1) {
sum[mask] += b[i];
}
}
dp[mask] = -1;
int P = upper_bound(pref.begin(), pref.end(), sum[mask]) - pref.begin();
for (int i = 0; i < M; i++) {
if ((mask >> i) & 1) {
if (dp[mask ^ (1 << i)] == P || (dp[mask ^ (1 << i)] == P - 1 && pref[P - 1] == sum[mask])) {
dp[mask] = P;
}
}
}
}
cout << (dp.back() == N + 1 ? "YES\n" : "NO\n");
}
# | 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... |