이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |