제출 #493517

#제출 시각아이디문제언어결과실행 시간메모리
493517Christopher_은행 (IZhO14_bank)C++17
100 / 100
112 ms8576 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector<int> p(n), b(m); for (int &e : p) { cin >> e; } for (int &e : b) { cin >> e; } vector<int> left((1 << m), -1), dp((1 << m), -1); left[0] = 0; dp[0] = 0; for (int mask = 0; mask < (1 << m); ++mask) { for (int last = 0; last < m; ++last) { if ((mask & (1 << last)) == 0) { continue; } int prev = mask & ~(1 << last); if (dp[prev] == -1) { continue; } int new_amt = left[prev] + b[last]; int cur = p[dp[prev]]; if (new_amt < cur) { dp[mask] = dp[prev]; left[mask] = new_amt; } else if (new_amt == cur) { dp[mask] = dp[prev] + 1; left[mask] = 0; } } if (dp[mask] == n) { cout << "YES\n"; return 0; } } cout << "NO\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...