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>
using namespace std;
#define ll long long
#define bit(mask, i) ((mask >> i) & 1)
const int ar = 20;
int n, m, a[ar], b[ar];
pair<int, int> dp[1 << 20];
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> m;
for(int i = 0; i < n; ++i) cin >> a[i];
for(int i = 0; i < m; ++i) cin >> b[i];
for(int i = 1; i < (1 << m); ++i) dp[i].first = -1;
for(int mask = 0; mask < (1 << m); ++mask) {
for(int i = 0; i < m; ++i) if(bit(mask, i)) {
auto [sz, val] = dp[mask ^ (1 << i)];
if(sz == -1) continue;
if(val + b[i] == a[sz]) dp[mask] = {sz + 1, 0};
else if(val + b[i] < a[sz]) dp[mask] = {sz, b[i] + val};
}
if(dp[mask].first == n) return cout << "YES\n", 0;
}
cout << "NO\n";
}
Compilation message (stderr)
bank.cpp: In function 'int main()':
bank.cpp:19:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
19 | auto [sz, val] = dp[mask ^ (1 << i)];
| ^
# | 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... |