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>
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, m;
std::cin >> n >> m;
std::vector<int> a(n), b(m);
for (int i = 0; i < n; ++i) {
std::cin >> a[i];
}
for (int i = 0; i < m; ++i) {
std::cin >> b[i];
}
std::vector<std::pair<int, int>> dp(1 << m);
dp[0] = {0, 0};
for (int s = 0; s < (1 << m); ++s) {
dp[s] = {0, 0};
for (int j = 0; j < m; ++j) {
if (s & (1 << j)) {
auto option = dp[s ^ (1 << j)];
option.second += b[j];
if (option.second == a[option.first]) {
option.first++;
option.second = 0;
}
dp[s] = std::max(dp[s], option);
}
}
if (dp[s].first == n) {
std::cout << "YES\n";
return 0;
}
}
std::cout << "NO\n";
return 0;
}
# | 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... |