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
#define MAX 20
int a[MAX], b[MAX], f[1 << MAX], l[1 << MAX];
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
// freopen("test.inp", "r", stdin); freopen("test.out", "w", stdout);
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < m; i++) cin >> b[i];
memset(f, -1, sizeof f);
f[0] = 0;
for (int mask = 0; mask < (1 << m); mask++) {
for (int j, cur = mask; cur; cur ^= -cur & cur) {
j = __builtin_ctz(cur);
if (f[mask ^ (1 << j)] == -1) continue;
int newleft = l[mask ^ (1 << j)] + b[j];
if (newleft == a[f[mask ^ (1 << j)]]) {
f[mask] = f[mask ^ (1 << j)] + 1;
l[mask] = 0;
}
else if (newleft < a[f[mask ^ (1 << j)]]) {
f[mask] = f[mask ^ (1 << j)];
l[mask] = newleft;
}
}
if (f[mask] == n) return cout << "YES", 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... |