#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define inf LLONG_MAX
#define ti tuple<int,int,int>
const int lim=20000;
signed main(){
int n,m;cin>>n>>m;
vector<int>a(n+10);for(int i=1;i<=n;i++)cin>>a[i];
vector<int>b(m+10);for(int i=0;i<m;i++)cin>>b[i];
vector<int>sum[lim+10];
for(int i=0;i<(1<<m);i++){
int cur=0;
for(int j=0;(1<<j)<=i;j++){
if(i&(1<<j)) cur+=b[j];
}
sum[cur].pb(i);
}
int dp[n+10][1<<m];
memset(dp,0,sizeof(dp));
for(auto x:sum[a[1]]){
dp[1][x]=1;
if(n==1){
cout<<"YES";
return 0;
}
}
for(int i=2;i<=n;i++){
for(int j=0;j<(1<<m);j++){
for(auto x:sum[a[i]]){
if(!(x&j) && dp[i-1][j]){
dp[i][(x|j)]=1;
}
}
if(i==n && dp[n][j]){
cout<<"YES";
return 0;
}
}
}
cout<<"NO";
}
// dp[i][taken]
// reach 1 dengan mask taken
// 1. whether the b can make the n
// 2. 10! brute force
// 3.
// 4.
// 11
// 12
// 13 -> kalau gaada
// 14 harus sama semua
# | 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... |