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 <bits/stdc++.h>
#define int long long
#define vi vector<int>
using namespace std;
signed main() {
int ppl, banknote;
cin >> ppl >> banknote;
vi ppls(ppl), banknotes(banknote), left(1 << banknote, -1), paid(1 << banknote, -1);
for (int i = 0; i < ppl; i++) cin >> ppls[i];
for (int i = 0; i < banknote; i++) cin >> banknotes[i];
left[0] = 0;
paid[0] = 0;
for (int mask = 0; mask < (1 << banknote); mask++) {
for (int last = 0; last < banknote; last++) {
if ((mask & (1 << last)) == 0) continue;
int prev = mask & ~(1 << last);
if (paid[prev] != -1) {
int cur = left[prev] + banknotes[last]; // current ppl
int curm = ppls[paid[prev]]; // target money for current ppl
if (cur < curm) {
paid[mask] = paid[prev];
left[mask] = cur;
}
else if (cur == curm) {
paid[mask] = paid[prev] + 1;
left[mask] = 0;
}
}
}
if (paid[mask] == ppl) {
cout << "YES" << endl;
return 0;
}
}
cout << "NO" << endl;
}
# | 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... |