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;
const int mxN = 20;
pair<int, int> dp[(1 << mxN) + 5];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> v(n), bnotes(m);
for(int i = 0; i < n; i++) {
cin >> v[i];
}
for(int i = 0; i < m; i++) {
cin >> bnotes[i];
}
for(int mask = 1; mask < (1 << m); mask++) {
for(int i = 0; i < m; i++) {
if(mask & (1 << i)) {
int prev = mask ^ (1 << i);
int sc = dp[prev].second;
pair<int, int> best = dp[prev];
if(sc + bnotes[i] == v[dp[prev].first]) {
best.first++;
best.second = 0;
}
else {
best.second += bnotes[i];
}
dp[mask] = max(best, dp[mask]);
}
}
}
cout << (dp[(1 << m) - 1].first == n ? "YES" : "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... |