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 <iostream>
#include <array>
const int MAX_N = 21;
std::array<int, MAX_N> As, Bs;
std::array<std::pair<int, int>, (1 << MAX_N)> dp;
int solve(int n, int m) {
for (int s = 1; s < (1 << m); ++s) {
for (int i = 0; i < m; ++i) {
if (s & (1 << i)) {
if (dp[s].first <= dp[s ^ (1 << i)].first) {
dp[s].first = dp[s ^ (1 << i)].first;
dp[s].second = dp[s ^ (1 << i)].second + Bs[i];
if (dp[s].second == As[dp[s].first + 1]) {
dp[s].first++;
dp[s].second = 0;
}
}
}
}
}
return dp[(1 << n) - 1].first;
}
int main() {
int n, m; std::cin >> n >> m;
for (int i = 0; i < n; ++i) {
std::cin >> As[i];
}
for (int i = 0; i < m; ++i) {
std::cin >> Bs[i];
}
int s = solve(n, m);
if (s == n - 1) {
std::cout << "YES" << std::endl;
} else {
std::cout << "NO" << std::endl;
}
}
# | 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... |