This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |