#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int ok=1;
vector<vector<int>>gp;
void stugum(int num){
for(auto &x:gp[num]){
if(x^num){
ok=0;
}
stugum(x);
}
}
void solve(){
int n,m;
cin>>n>>m;
vector<int>a(n),b(m);
for(int i=0;i<n;i++){
cin>>a[i];
}
int sum=0;
for(int i=0;i<m;i++){
cin>>b[i];
sum+=b[i];
}
gp=vector<vector<int>>((1<<m));
for(int i=0;i<(1<<n);i++){
int ans=0;
for(int j=0;j<m;j++){
if(i & (1<<j)){
ans+=b[j];
}
}
gp[ans].push_back(i);
}
for(int i=0;i<n;i++){
stugum(a[i]);
}
if(ok){
cout<<"YES"<<endl;
return;
}
cout<<"NO"<<endl;
}
int main(){
int t=1;
//cin>>t;
while(t--){
solve();
}
}
# | 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... |