Submission #429392

#TimeUsernameProblemLanguageResultExecution timeMemory
429392SansPapyrus683Bank (IZhO14_bank)C++17
19 / 100
112 ms8524 KiB
#include <iostream> #include <vector> #include <algorithm> using std::cout; using std::endl; using std::vector; /** * https://oj.uz/problem/view/IZhO14_bank * 2 6 * 9 10 * 5 4 8 6 3 11 should output NO */ int main() { int people_num; int note_num; std::cin >> people_num >> note_num; vector<int> people(people_num); vector<int> banknotes(note_num); for (int& p : people) { std::cin >> p; } for (int& b : banknotes) { std::cin >> b; } vector<int> leftover(1 << note_num); vector<int> people_covered(1 << note_num); leftover[0] = 0; // making base case explicit people_covered[0] = 0; for (int s = 0; s < (1 << note_num); s++) { for (int last = 0; last < note_num; last++) { if ((s & (1 << last)) == 0) { continue; } int prev = s & ~(1 << last); int new_amt = leftover[prev] + banknotes[last]; int curr_target = people[people_covered[prev]]; if (new_amt < curr_target) { people_covered[s] = people_covered[prev]; leftover[s] = new_amt; } else if (new_amt == curr_target) { people_covered[s] = people_covered[prev] + 1; } } if (people_covered[s] == people_num) { cout << "YES" << endl; return 0; } } cout << "NO" << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...