제출 #1077785

#제출 시각아이디문제언어결과실행 시간메모리
1077785hahahaha은행 (IZhO14_bank)C++17
100 / 100
93 ms8644 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...