/**
* author: tuncypasha
* file: c.cpp
* created: 17.02.2026 22:58
**/
#include <bits/stdc++.h>
#include <bits/extc++.h>
#define pasha ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(v) begin(v), end(v)
using namespace std;
using namespace __gnu_pbds;
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
constexpr int N = 2e5 + 5, LG = 20, oo = 1e16;
vector<int> v[N];
bool ok(int mask, int submask) {
for (int i = LG - 1; i >= 0; --i) {
if ((submask & (1LL << i)) && !(mask & (1LL << i)))
return false;
}
return true;
}
void _() {
int n, m;
cin >> n >> m;
vector<int> a(n + 1);
for (int i = 1; i <= n; ++i)
cin >> a[i];
vector<int> b(m);
for (int i = 0; i < m; ++i)
cin >> b[i];
vector<vector<int>> dp((1LL << m) + 5, vector<int>(n + 5, 0));
vector<int> sum((1LL << m) + 5, 0);
for (int mask = 0; mask < (1LL << m); ++mask) {
int S = 0;
for (int i = 0; i < m; ++i) {
if (mask & (1LL << i))
S += b[i];
}
sum[mask] = S, v[S].pb(mask);
}
dp[0][0] = 1;
for (int i = 1; i <= n; ++i) {
for (int mask = 0; mask < (1LL << m); ++mask) {
for (int &submask : v[a[i]]) {
if (!ok(mask, submask))
continue;
int out = (mask ^ submask);
dp[mask][i] |= (dp[out][i - 1]);
}
}
}
for (int mask = 0; mask < (1LL << m); ++mask) {
if (dp[mask][n])
return cout << "YES" << '\n', void();
}
cout << "NO" << '\n', void();
}
signed main() {
pasha
int t = 1;
// cin >> t;
for (int cs = 1; cs <= t; ++cs) {
_();
// cout << '\n';
}
}
| # | 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... |