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() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> p(n), b(m);
for (int &e : p) {
cin >> e;
}
for (int &e : b) {
cin >> e;
}
vector<int> left((1 << m), -1), dp((1 << m), -1);
left[0] = 0;
dp[0] = 0;
for (int mask = 0; mask < (1 << m); ++mask) {
for (int last = 0; last < m; ++last) {
if ((mask & (1 << last)) == 0) {
continue;
}
int prev = mask & ~(1 << last);
if (dp[prev] == -1) {
continue;
}
int new_amt = left[prev] + b[last];
int cur = p[dp[prev]];
if (new_amt < cur) {
dp[mask] = dp[prev];
left[mask] = new_amt;
} else if (new_amt == cur) {
dp[mask] = dp[prev] + 1;
left[mask] = 0;
}
}
if (dp[mask] == n) {
cout << "YES\n";
return 0;
}
}
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... |