Submission #898557

#TimeUsernameProblemLanguageResultExecution timeMemory
898557vaneaBank (IZhO14_bank)C++14
100 / 100
98 ms8972 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int mxN = 20; pair<int, int> dp[(1 << mxN) + 5]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; vector<int> v(n), bnotes(m); for(int i = 0; i < n; i++) { cin >> v[i]; } for(int i = 0; i < m; i++) { cin >> bnotes[i]; } for(int mask = 1; mask < (1 << m); mask++) { for(int i = 0; i < m; i++) { if(mask & (1 << i)) { int prev = mask ^ (1 << i); int sc = dp[prev].second; pair<int, int> best = dp[prev]; if(sc + bnotes[i] == v[dp[prev].first]) { best.first++; best.second = 0; } else { best.second += bnotes[i]; } dp[mask] = max(best, dp[mask]); } } } cout << (dp[(1 << m) - 1].first == n ? "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...