#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];
bool 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];
REP(mask,(1<<m))
{
int tmp = 0;
REP(i,m) if(mask&(1<<i)) tmp += b[i];
if(tmp > max_val || !cnt[tmp]) continue;
g[tmp].pub(mask);
}
dp[0][0] = true;
REP(i,n)
{
bool check = false;
REP(mask,(1<<m))
{
if(!dp[i][mask]) continue;
for(int submask : g[a[i+1]])
{
if((submask & mask) == 0)
dp[i+1][mask | submask] = check = true;
}
}
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... |