제출 #672413

#제출 시각아이디문제언어결과실행 시간메모리
672413moday_morning은행 (IZhO14_bank)C++17
100 / 100
88 ms16752 KiB
#include <bits/stdc++.h> #define int long long using namespace std; void solve() { int n, m; cin >> n >> m; vector <int> a(n), vm(m), b((1 << m)), dp((1 << m), -1); for(int i = 0; i < n; i++) { cin >> a[i]; } for(int j = 0; j < m; j++){ cin >> vm[j]; } dp[0] = 0; b[0] = 0; for (int s = 1; s < (1 << m); s++) { for (int i = 0; i < m; i++){ if ((s & (1 << i))) { int pr = s - (1 << i); if (dp[pr] == n) { dp[s] = n; break; } if (dp[pr] == -1) { continue; } if (b[pr] + vm[i] < a[dp[pr]]) { dp[s] = dp[pr]; b[s] = b[pr] + vm[i]; break; } if (b[pr] + vm[i] == a[dp[pr]]) { dp[s] = dp[pr] + 1; b[s] = 0; break; } } } } if (dp[(1 << m) - 1] == n) { cout << "YES\n"; } else { cout << "NO\n"; } } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; // cin >> t; while (t--) { solve(); } } /* 3 0 0 0 9 8 5 7 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...