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 pii pair <int, int>
#define fi first
#define se second
const int N = 22;
const int inf = 1e9 + 7;
pii f[(1 << N) + 1];
int a[N], b[N];
int n, m;
bool bit(int x, int i) {
return ((x >> i) & 1);
}
int flip (int x, int i) {
return (x ^ (1 << i));
}
int main () {
ios_base :: sync_with_stdio (0);
cin.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 mask = 0; mask < (1 << m); mask ++) {
for (int i = 0; i <=m; i ++) {
if (bit (mask, i)) {
pii cur = f[flip (mask, i)];
if (cur.se + b[i] < a[cur.fi]) {
f[mask] = max (f[mask], {cur.fi, cur.se + b[i]});
}
else if (cur.se + b[i] == a[cur.fi]){
f[mask] = max (f[mask], {cur.fi + 1, 0});
}
}
}
if (f[mask].fi == n) {
cout << "YES";
return 0;
}
}
cout << "NO";
return 0;
}
# | 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... |