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 fi first
#define se second
using namespace std;
typedef pair<int, int> ii;
int n, m;
int a[25], b[25];
ii f[1<<20];
int bit(int x, int i) {
return (x>>i)&1;
}
ii calc(ii x, int y) {
if (x.fi == n+1) return x;
if (x.se + y > a[x.fi]) return {-1, -1};
if (x.se + y == a[x.fi]) return {x.fi+1, 0};
return {x.fi, x.se+y};
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= m; i++) cin >> b[i];
f[0] = {1, 0};
for (int o = 1; o < (1<<m); o++) {
f[o] = {-1, -1};
for (int i = 1; i <= m; i++) {
if (!bit(o, i-1)) continue;
int y = o^(1<<(i-1));
if (f[y] == ii{-1, -1}) continue;
f[o] = max(f[o], calc(f[y], b[i]));
}
}
ii X = f[(1<<m)-1];
cout << (X.fi != n + 1 ? "NO" : "YES");
}
# | 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... |