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;
int n, m;
vector<int> a, b;
namespace sub4 {
bool check() {
return n <= 20 && m <= 20;
}
pair<int, int> f[1 << 20];
void solve() {
for (int i = 0; i < (1 << m); i++) {
f[i] = {-1, -1};
}
f[0] = {0, 0};
for (int msk = 0; msk < (1 << m); msk++) {
for (int lst = 0; lst < m; lst++) {
if (!(msk >> lst & 1)) {
continue;
}
int prv = msk ^ (1 << lst);
if (f[prv].first == -1) {
continue;
}
int pi = f[prv].first;
int pj = f[prv].second;
if (pj + b[lst] < a[pi]) {
f[msk] = {pi, pj + b[lst]};
} else if (pj + b[lst] == a[pi]) {
f[msk] = {pi + 1, 0};
}
}
if (f[msk].first == n) {
cout << "YES" << '\n';
return;
}
}
cout << "NO" << '\n';
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
a.resize(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
b.resize(m);
for (int i = 0; i < m; i++) {
cin >> b[i];
}
if (sub4::check()) {
sub4::solve();
exit(0);
}
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... |