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 <vector>
#include <algorithm>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> sal(n);
for (int i = 0; i < n; i++) {
cin >> sal[i];
}
vector<int> bank(m);
for (int j = 0; j < m; j++) {
cin >> bank[j];
}
// dp on which bank notes we have used, <current user, amount money given>
vector<pair<int, int>> dp(1 << m, make_pair(-1, 0));
dp[0] = make_pair(0, 0);
for (int i = 0; i < (1 << m); i++) {
if (dp[i].first == -1) {
continue;
}
if (dp[i].first == n) {
cout << "YES\n";
return 0;
}
for (int j = 0; j < m; j++) {
if ((1 << j) & i) {
continue;
}
pair<int, int> cur = dp[i];
cur.second += bank[j];
if (cur.second > sal[dp[i].first]) {
continue;
}
if (cur.second == sal[dp[i].first]) {
cur.first++;
cur.second = 0;
}
dp[i ^ (1 << j)] = cur;
}
}
cout << "NO\n";
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... |