#include<bits/stdc++.h>
using namespace std;
using ll = long long;
bool f = 0;
vector<int>a;
vector<bool>vis;
vector<vector<int>>gp(1e3 + 5);
void dfs(int mask, int u)
{
vis[mask] = 1;
if (u == -1)
{
f = 1;
return;
}
for (int& v : gp[a[u]])
{
if ((v & mask) != v || vis[mask ^ v]) continue;
vis[mask ^ v] = 1;
dfs(mask ^ v, u - 1);
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m; cin >> n >> m;
vector<int> b(m);
a = vector<int>(n);
vis = vector<bool>(2e5);
for (int& i : a) cin >> i;
for (int& i : b) cin >> i;
for (int i = 1; i < (1 << m); i++)
{
int sum = 0;
for (int j = 0; j < m; j++)
{
if (i & (1 << j))
{
sum += b[j];
}
}
if(sum > 1e3) continue;
gp[sum].push_back(i);
}
dfs((1 << m) - 1, n - 1);
if (f) cout << "YES\n";
else cout << "NO\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... |