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 DEBUG(x) cout << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
int main() {
int n, m;
cin >> n >> m;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<int> b(m);
for (int i = 0; i < m; ++i) {
cin >> b[i];
}
// dp of subset X -> num of people in prefix, leftover sum.
// left-over must equal be for num of people and set
// so we must maximize prefix
vector<pair<int, int>> dp(1 << m, {-1, -1});
dp[0] = {0, 0};
bool ok = false;
for (int i = 1; i < (1 << m); ++i) {
for (int j = 0; j < m; ++j) {
if (!(i & (1 << j))) continue; // j not in i
auto& [cnt, leftover] = dp[i ^ (1 << j)];
if (cnt == -1) continue; // impossible state
int target = a[cnt]; // current salary we try to fill
// only one can be always satisfied!
if (leftover + b[j] < target) {
dp[i] = {cnt, leftover + b[j]};
} else if (leftover + b[j] == target) {
dp[i] = {cnt + 1, 0};
}
}
if (dp[i].first == n) {
ok = true;
break;
}
}
cout << (ok ? "YES" : "NO");
}
Compilation message (stderr)
bank.cpp: In function 'int main()':
bank.cpp:28:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
28 | auto& [cnt, leftover] = dp[i ^ (1 << j)];
| ^
# | 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... |