//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")
//#pragma GCC optimize("trapv")
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define mpr make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int nmax = 20, mod = 1000000007, inf = 2000010000, key = 200003, lg = 20, block = 300;
const ll infll = 4000000000000000000;
const ld eps = 1e-9;
int targets[nmax], banknotes[nmax];
int dp[1 << nmax], sum[1 << nmax];
void solve()
{
int n, m;
cin >> n >> m;
for(int i = 0; i < n; i++)
cin >> targets[i];
targets[n] = -1;
for(int i = 0; i < m; i++)
cin >> banknotes[nmax];
for(int i = 1; i < (1 << m); i++) {
for(int j = 0; j < m; j++) {
if((i >> j) & 1)
sum[i] += banknotes[j];
}
for(int j = i; j > 0; j = (j - 1) & i) {
int cnt = dp[i ^ j];
if(sum[j] == targets[cnt])
dp[i] = max(dp[i], dp[i ^ j] + 1);
}
if(dp[i] == n - 1) {
cout << "YES\n";
return ;
}
}
cout << "NO\n";
return ;
}
int main()
{
//freopen("movie.in","r",stdin);
//freopen("movie.out","w",stdout);
ios_base::sync_with_stdio(0);cin.tie(0);
srand(8713);
//init();
int t = 1;
//cin >> t;
//int t_ = t;
//t = rdi();
while(t--) {
//cout << "Case #" << t_ - t << ": ";
solve();
}
//flush();
return 0;
}
/*
8 11
7 3 5 12 2 7 3 4
*/
| # | 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... |