#include <bits/stdc++.h>
#define ll long long
#define ent '\n'
#define pb push_back
#define all(x) x.begin(),x.end()
#define PRaim_bek_abi ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
const int N = 1e5+5;
const int MOD = 1e9+7;
int n , m , a[N] , b[N];
bool dp[N];
set<int>v;
void rec(int i , set<int>s){
if (i == n + 1){
cout << "YES";
exit(0);
}
if (s.size() == 0) return;
int ns = s.size();
for (int mask = 0; mask < (1 << ns); mask++){
int sum = 0;
set<int>nw = s;
auto it = s.begin();
for (int j = 0; j < s.size(); j++){
if (mask & (1 << j)){
sum += b[*it];
nw.erase(nw.find(*it));
}
it++;
}
if (sum == a[i]){
rec(i + 1 , nw);
}
}
}
void easy(){
cin >> n >> m;
for (int i = 1; i <= n; i++){
cin >> a[i];
}
for (int i = 1; i <= m; i++){
cin >> b[i];
v.insert(i);
}
rec(1 , v);
cout << "NO";
}
signed main(){
PRaim_bek_abi
int t=1;
//cin>>t;
while(t--) easy();
}
| # | 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... |