Submission #493518

#TimeUsernameProblemLanguageResultExecution timeMemory
493518Christopher_Bank (IZhO14_bank)C++17
100 / 100
115 ms8592 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 i = 0; i < n; ++i) { cin >> p[i]; } for (int i = 0; i < m; ++i) { cin >> b[i]; } vector<int> dp((1 << m), -1), left((1 << m), -1); dp[0] = left[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 money = left[prev] + b[last]; int cur = p[dp[prev]]; if (cur > money) { left[s] = money; dp[s] = dp[prev]; } else if (cur == money) { left[s] = 0; dp[s] = dp[prev] + 1; } } if (dp[s] == 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...