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;
using ll = long long;
pair<int, int> dp[1 << 21];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
// freopen("", "r", stdin);
// freopen("", "w", stdout);
int n, m; cin >> n >> m;
vector<int> people(n);
for (int i = 0; i < n; i++) {
cin >> people[i];
}
vector<int> note(m);
for (int i = 0; i < m; i++) {
cin >> note[i];
}
dp[0] = {0, 0};
for (int i = 1; i < (1 << m); i++) {
dp[i] = {-1, -1};
for (int j = 0; j < m; j++) {
if (i & (1 << j)) {
int subset = i - (1 << j);
auto prev = dp[subset];
prev.second += note[j];
if (prev.second == people[prev.first]) {
prev.first++;
prev.second = 0;
}
if (prev.first == n) {
cout << "YES";
return 0;
}
dp[i] = max(dp[i], prev);
}
}
}
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... |