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 i = 0; i < n; ++i) {
cin >> p[i];
}
for (int i = 0; i < m; ++i) {
cin >> b[i];
}
vector<int> dp((1 << m), -1), left((1 << m), -1);
dp[0] = left[0] = 0;
for (int s = 0; s < (1 << m); ++s) {
for (int last = 0; last < m; ++last) {
if ((s & (1 << last)) == 0) {
continue;
}
int prev = s & ~(1 << last);
if (dp[prev] == -1) {
continue;
}
int money = left[prev] + b[last];
int cur = p[dp[prev]];
if (cur > money) {
left[s] = money;
dp[s] = dp[prev];
} else if (cur == money) {
left[s] = 0;
dp[s] = dp[prev] + 1;
}
}
if (dp[s] == 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... |