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 int long long
const int N = 20;
int n, m, a[N + 5], b[N + 5];
int lef[(1 << N) + 5];
int done[(1 << N) + 5];
signed main() {
ios::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];
memset(lef, -1, sizeof lef);
memset(done, -1, sizeof done);
lef[0] = 0;
done[0] = 0;
for (int s = 0; s < (1 << m); s++) {
for (int i = 0; i < m; i++) {
if ((s >> i) & 1) {
int t = s ^ (1 << i);
if (done[t] == -1) continue;
int x = lef[t] + b[i];
int need = a[done[t]];
if (x < need) {
done[s] = done[t];
lef[s] = x;
} else if (x == need) {
done[s] = done[t] + 1;
lef[s] = 0;
}
}
}
if (done[s] == 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... |