#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = (1 << 20);
int leftover[MAX], dp[MAX];
void solve() {
memset(leftover, -1, sizeof(leftover)), memset(dp, -1, sizeof(dp));
int n, m;
cin >> n >> m;
vector<int> a(n), b(m);
for (int &p : a) {
cin >> p;
}
for (int &b : b) {
cin >> b;
}
leftover[0] = 0, dp[0] = 0;
for (int mask = 0; mask < (1 << m); mask++) {
for (int i = 0; i < m; i++) {
if ((mask & (1 << i)) == 0) continue;
int prev = mask & ~(1 << i);
if (dp[prev] == -1) continue;
int next = leftover[prev] + b[i], target = a[dp[prev]];
if (next < target) {
dp[mask] = dp[prev];
leftover[mask] = next;
} else if (next == target) {
dp[mask] = dp[prev] + 1;
leftover[mask] = 0;
}
}
if (dp[mask] == n) {
cout << "YES\n";
return;
}
}
cout << "NO\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
# | 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... |