Submission #887585

#TimeUsernameProblemLanguageResultExecution timeMemory
887585mertozelBank (IZhO14_bank)C++11
100 / 100
103 ms8796 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(){ int n, m; cin >> n >> m; vector<int> people(n), banknotes(m); for(int &i : people) cin >> i; for(int &i : banknotes) cin >> i; vector<int> prefix_people(1<<m, -1), leftover(1<<m, -1); prefix_people[0] = 0, leftover[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(prefix_people[prev] == -1 || leftover[prev] == -1) continue; int our_sum = leftover[prev] + banknotes[last]; int our_man = prefix_people[prev]; if(our_sum < people[our_man]) { leftover[s] = our_sum; prefix_people[s] = prefix_people[prev]; } else if(our_sum == people[our_man]) { prefix_people[s] = prefix_people[prev]+1; leftover[s] = 0; } } if(prefix_people[s] == n) {cout << "YES"; return 0;} } cout << "NO"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...