#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// freopen("visitfj.in", "r", stdin);
// freopen("visitfj.out", "w", stdout);
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n,m; cin>>n>>m; vector<int>a(n+1); vector<int>b(m);
for(int i=1; i<=n; i++){
cin>>a[i];
}
for(int i=0; i<m; i++){
cin>>b[i];
}
vector<vector<int>>dp(n+1,vector<int>((1<<m),0)); dp[0][0]=1;
for(int i=0; i<n; i++){
for(int j=0; j<(1<<m); j++){
if(dp[i][j]==0) continue;
vector<int>ava;
for(int k=0; k<m; k++){
if(j&(1<<k))continue;
ava.push_back(b[k]);
}
for(int k=0; k<(1<<ava.size()); k++){
int cur=0;
for(int q=0; q<ava.size(); q++){
if(k&(1<<q)) cur+=ava[q];
}
if(cur==a[i+1])dp[i+1][j|k]=1;
}
}
}
bool ans=false;
for(int i=0; i<(1<<m); i++){
if(dp[n][i]) ans=true;
}
if(ans)cout<<"YES";
else cout<<"NO";
}
# | 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... |