Submission #991273

#TimeUsernameProblemLanguageResultExecution timeMemory
991273hippo123Bank (IZhO14_bank)C++17
100 / 100
87 ms8624 KiB
#include <bits/stdc++.h> using namespace std; const int N = 20; int n, m, a[N], b[N]; pair<int, int> dp[(1 << N)]; int main() { cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) cin >> b[i]; dp[0] = {0, 0}; bool pos = false; for (int s = 0; s < (1 << m); s++) { if (dp[s].first == n) { pos = true; break; } for (int j = 0; j < m; j++) { if (s & (1 << j)) continue; pair<int, int> new_state; if (a[dp[s].first] == dp[s].second + b[j]) { new_state = {dp[s].first + 1, 0}; } else new_state = {dp[s].first, dp[s].second + b[j]}; dp[s | (1 << j)] = max(dp[s | (1 << j)], new_state); } } cout << (pos ? "YES" : "NO"); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...