#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define F first
#define S second
#define ll long long
#define int ll
#define pii pair<int, int>
#define io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define M_PI 3.14159265358979323846
#define all(v) v.begin(), v.end()
#define pss pair<string, string>
#define no cout<<"NO"<<endl;
#define yes cout<<"YES"<<endl;
#define imp cout<<-1<<endl;
#define was cout<<ans<<endl;
#define flu cout.flush();
#define Endl endl
const int N = 200009;
const int mod = 1e9+7;
int yx=0;
int m, n;
vector<int>b, a;
void f(int ind, vector<int>q){
if(ind==m){
yes;
exit(0);
}
int k=b[ind], cem=0;
map<int, int>used;
vector<int>p;
int sz=q.size();
for(int i=0; i<(1<<sz); i++){
cem=0;
for(int j=0; j<sz; j++){
if(i&(1<<j)){
cem+=q[j];
used[j]++;
}
}
if(cem==k){
for(int j=0; j<n; j++){
if(used[j]==0){
p.pb(q[j]);
}
}
f(ind+1, p);
}
for(int j=0; j<n; j++){
used[j]=0;
}
p.clear();
}
}
void solve(){
cin>>m>>n;
for(int i=0; i<m; i++){
int x;
cin>>x;
b.pb(x);
}
for(int i=0; i<n; i++){
int x;
cin>>x;
a.pb(x);
}
sort(all(a));
sort(all(b));
/*
for(int i=0; i<(1<<3); i++){
for(int j=0; j<3; j++){
if(i&(1<<j)){
cout<<j<<" ";
}
}
cout<<endl;
}*/
f(0, a);
no;
}
signed main(){
io;
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... |