Submission #994027

#TimeUsernameProblemLanguageResultExecution timeMemory
994027kchaitanya06Bank (IZhO14_bank)C++14
100 / 100
87 ms8792 KiB
#include<bits/stdc++.h> using namespace std; void solve() { int n, m; cin >> n >> m; vector<int> people(n); for (int &p : people) cin >> p; vector<int> bank_notes(m); for (int &b : bank_notes) cin >> b; vector<int> left_over(1 << m, -1); vector<int> people_covered(1 << m, -1); left_over[0] = 0; people_covered[0] = 0; for (int mask = 1; mask < 1 << m; mask++) { for (int j = 0; j < m; j++) { if (mask & 1 << j && people_covered[mask ^ (1 << j)] != -1) { int rem = left_over[mask ^ (1 << j)] + bank_notes[j]; int people_ind = people_covered[mask ^ (1 << j)]; if (rem < people[people_ind]) { left_over[mask] = rem; people_covered[mask] = people_covered[mask ^ (1 << j)]; } else if (rem == people[people_ind]) { left_over[mask] = 0; people_covered[mask] = people_covered[mask ^ (1 << j)] + 1; } } } if (people_covered[mask] == n) { cout << "YES" << endl; return; } } cout << "NO" << endl; } int main() { solve(); 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...