Submission #955529

#TimeUsernameProblemLanguageResultExecution timeMemory
955529imannBank (IZhO14_bank)C++17
100 / 100
89 ms16988 KiB
#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) { dp.fill({-1, 0}); 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 << m) - 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...