Submission #992053

#TimeUsernameProblemLanguageResultExecution timeMemory
992053CallieBank (IZhO14_bank)C++11
100 / 100
139 ms58032 KiB
#include <iostream> #include <utility> #include <vector> using namespace std; int main() { int people, banknotes; cin >> people >> banknotes; vector<int> plist(people); vector<int> blist(banknotes); for(int i = 0; i < people; i++) { cin >> plist[i]; } for(int i = 0; i < banknotes; i++) { cin >> blist[i]; } vector<vector<int> > dp((1 << banknotes), vector<int>(2)); for(int i = 0; i < (1 << banknotes); i++) { dp[i][0] = -1; dp[i][1] = -1; } dp[0][0] = 0; dp[0][1] = 0; for(int i = 0; i < (1 << banknotes); i++) { for(int j = 0; j < banknotes; j++) { if((i & (1 << j)) == 0) continue; if(dp[i ^ (1 << j)][0] == -1) continue; if(dp[i ^ (1 << j)][0] == banknotes) continue; int p = dp[i ^ (1 << j)][0]; int b = dp[i ^ (1 << j)][1]; if(b + blist[j] < plist[p]) { dp[i][0] = p; dp[i][1] = b + blist[j]; } else if(b + blist[j] <= plist[p]) { dp[i][0] = p + 1; dp[i][1] = 0; } } } for(int i = 0; i < (1 << banknotes); i++) { if(dp[i][0] == people) { 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...