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;
#define int long long int
void solve() {
int n, m;
cin >> n >> m;
vector<int> a(n), b(m);
vector<pair<int, int>> dp(1<<m, {-1, -1});
for (int &x : a) {
cin >> x;
}
for (int &x : b) {
cin >> x;
}
dp[0] = {0, 0};
for (int i = 1; i < 1 << m; i++) {
for (int j = 0; j < m;j++) {
if (!(i&(1<<j))) {
continue;
}
int x = i^(1<<j);
if (dp[x].second == -1) {
continue;
}
if (dp[x].second+b[j] < a[dp[x].first]) {
dp[i].first = dp[x].first;
dp[i].second = dp[x].second+b[j];
} else if (dp[x].second+b[j] == a[dp[x].first]) {
dp[i].first = dp[x].first+1;
dp[i].second = 0;
}
}
if (dp[i].first == n) {
cout << "YES" << endl;
return;
}
}
cout << "NO" << endl;
}
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
t = 1;
while(t--) {
solve();
}
}
# | 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... |