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 nl '\n'
template <typename T>
inline bool ckmax(T& x, const T& y) {
return x < y ? x = y, 1 : 0;
}
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int N, M;
std::cin >> N >> M;
std::vector<int> A(N), B(M);
std::vector<int> pref(N + 1);
for (int i = 0; i < N; i++) {
std::cin >> A[i];
pref[i + 1] = pref[i] + A[i];
}
for (int i = 0; i < M; i++) {
std::cin >> B[i];
}
std::vector<int> dp(1 << M);
dp[0] = 0;
bool ok = 0;
for (int mask = 0; mask < (1 << M); mask++) {
int upto = dp[mask];
if (upto == N) {
ok = 1;
break;
}
int sum = 0;
for (int j = 0; j < M; j++) {
if (mask >> j & 1) {
sum += B[j];
}
}
int remain = sum - pref[upto];
for (int j = 0; j < M; j++) {
if (mask >> j & 1) continue;
ckmax(dp[mask ^ (1 << j)], upto + (remain + B[j] == A[upto]));
}
}
std::cout << (ok ? "YES" : "NO") << nl;
}
# | 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... |