Submission #1072289

#TimeUsernameProblemLanguageResultExecution timeMemory
1072289horezusholBank (IZhO14_bank)C++14
100 / 100
90 ms8640 KiB
#include<bits/stdc++.h> using namespace std; const char nl = '\n'; signed main() { int n; int m; std::cin >> n >> m; int a[n], b[m]; for (int i = 0; i < n; i ++) cin >> a[i]; for (int j = 0; j < m; j ++) cin >> b[j]; vector<int> sum(1 << m, -1); vector<int> dp(1 << m, -1); sum[0] = 0; dp[0] = 0; for (int s = 0; s < (1 << m); s++) { for (int last = 0; last < m; last++) { if ((s & (1 << last)) == 0) { continue; } int prev = s & ~(1 << last); if (dp[prev] == -1) { continue; } int new_amt = sum[prev] + b[last]; int curr_target = a[dp[prev]]; if (new_amt < curr_target) { dp[s] = dp[prev]; sum[s] = new_amt; } else if (new_amt == curr_target) { dp[s] = dp[prev] + 1; sum[s] = 0; } } if (dp[s] == n) { cout << "YES" << nl; return 0; } } cout << "NO" << nl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...