이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// https://oj.uz/problem/view/IZhO14_bank
#include <bits/stdc++.h>
using namespace std;
pair<int, int> better(pair<int, int> p1, pair<int, int> p2) {
if (p1.first != p2.first) {
return p1.first > p2.first ? p1 : p2;
}
return p1.second >= p2.second ? p1 : p2;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> A(n);
for (int& a : A) {
cin >> a;
}
vector<int> B(m);
for (int& b : B) {
cin >> b;
}
vector<pair<int, int>> dp(1 << m);
for (int bitmask = 1; bitmask < (1 << m); bitmask++) {
for (int last = 0; last < m; last++) {
if (!(bitmask & (1 << last))) {
continue;
}
int previous = bitmask ^ (1 << last);
auto [employee, remaining] = dp[previous];
int sum = remaining + B[last];
// Matches the current employee's salary, can go to the next one
pair<int, int> state;
if (sum == A[employee]) {
state = {employee + 1, 0};
}
// Push this banknote onto the leftover amount
else {
state = {employee, sum};
}
dp[bitmask] = better(dp[bitmask], state);
}
if (dp[bitmask].first == n) {
cout << "YES\n";
return 0;
}
}
cout << "NO\n";
}
# | 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... |