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 main () {
int n, m;
cin >> n >> m;
int ar[n], br[m];
for (int i = 0; i < n; i++) {
cin >> ar[i];
}
for (int i = 0; i < m; i++) {
cin >> br[i];
}
vector<int> dp(1<<n), cr;
cr.push_back(0);
for (int i = 0; i < n; i++) {
cr.push_back(cr.back() + ar[i]);
}
dp[0] = 1;
for (int msk = 0; msk < (1<<m); msk++) {
if (dp[msk]) {
int cur = 0;
for (int j = 0; j < m; j++) {
if ((msk>>j) & 1) {
cur += br[j];
}
}
int in = 0;
while (in + 1 < (int) cr.size() && cr[in + 1] <= cur) in++;
if (in == (int) cr.size() - 1) {
cout << "YES" << '\n';
return 0;
}
for (int j = 0; j < m; j++) {
if ((msk>>j) & 1) continue;
if (cur + br[j] <= cr[in]) {
dp[msk^(1<<j)] = 1;
}
}
}
}
cout << "NO" << '\n';
}
# | 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... |