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<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int a[25];
int b[25];
for (int i = 0; i < n; ++i) {
cin >> a[i + 1];
}
for (int i = 0; i < m; ++i) {
cin >> b[i];
}
vector<pair<int,int>> dp((1 << m));
for (int mask = 0; mask < (1 << m); ++mask) {
if (dp[mask].first == 0 && dp[mask].second == 0 && mask > 0) continue;
for (int i = 0; i < m; ++i) {
if ((mask & (1 << i))) continue;
int ost = a[dp[mask].first + 1] - dp[mask].second;
if (ost < b[i]) continue;
if (ost == b[i]) {
dp[(mask | (1 << i))].first = dp[mask].first + 1;
dp[(mask | (1 << i))].second = 0;
}
else {
dp[(mask | (1 << i))] = dp[mask];
dp[(mask | (1 << i))].second += b[i];
}
}
}
for (auto elem : dp) {
if (elem.first == n) {
cout << "YES";
return 0;
}
}
cout << "NO";
}
# | 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... |