#include <bits/stdc++.h>
using namespace std;
#define __Master_Moon__ int main()
#define ll long long
#define el "\n"
#define fi first
#define sq(x) (x)*(x)
#define se second
#define pub push_back
#define puf push_front
#define pii pair <int, int>
#define pll pair <long long, long long>
#define piii pair <int, pair <int, int>>
#define iiii pair <int, pair <int, pair <int, int>>>
#define plll pair <long long, pair <long long, long long>>
#define FOR(i, a, b) for(int i = (a);i <=(b);i++)
#define FO(i, a, b) for(int i = (a);i >= (b);i--)
#define REP(i, n) for(int i = 0;i < (n);i++)
long const maxn = 22;
long const MASK = (1<<20) + 2;
int a[maxn],b[maxn],n,m,max_val,cnt[1005];
int dp[maxn][MASK];
vector<int> g[1005];
void solve()
{
cin >> n >> m;
FOR(i,1,n)
{
cin >> a[i];
cnt[a[i]] = 1;
max_val = max(max_val,a[i]);
}
REP(i,m) cin >> b[i];
memset(dp,-1,sizeof dp);
REP(mask,(1<<m))
{
dp[0][mask] = 1;
int tmp = 0;
REP(i,m) if(mask&(1<<i)) tmp += b[i];
if(tmp > max_val || !cnt[tmp]) continue;
g[tmp].pub(mask);
}
FOR(i,1,n)
{
bool check = true;
REP(mask,(1<<m))
{
for(int submask : g[a[i]])
{
if((mask | submask) == mask)
dp[i][mask] = max(dp[i][mask],dp[i-1][mask^submask]);
}
if(dp[i][mask] == 1) check = false;
}
if(check)
{
cout << "NO";
return;
}
}
cout << "YES";
}
__Master_Moon__
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
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... |