#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <math.h>
#include <array>
#include <random>
#include <bitset>
#include <climits>
#include <cstring>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define endl '\n'
#define mod 1000000007
#define INF 0x3f3f3f3f
#define int long long
template <class x>
using ordered_set = tree<x, null_type, less<x>, rb_tree_tag, tree_order_statistics_node_update>;
typedef pair<int, int> ipair;
static inline int read()
{
int x = 0;char ch = getchar();
while (ch < '0' || ch>'9') ch = getchar();
while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
return x;
}
static inline void print(const int &x) {
if (x > 9) print(x / 10);
putchar('0' + x % 10);
}
bool f = 0;
int n, m, a[30];
int taken[30];
void solve(int asd, int x, int used, int sum = 0)
{
if(m == asd)
{
if(f) return;
if(sum == x)
{
for(int i = 0;i < 25;i++)
{
if(used&(1ll << i)) taken[i] = 1;
}
f = 1;
}
return;
}
solve(asd + 1, x, used, sum);
if(taken[asd]) return;
used |= (1ll << asd);
sum += a[asd];
solve(asd + 1, x, used, sum);
}
signed main()
{
cin.tie(0) -> sync_with_stdio(0);
cin >> n >> m;
int b[n];
for(int i = 0;i < n;cin >> b[i++]);
for(int i = 0;i < m;cin >> a[i++]);
// sort(b, b + n);
// sort(a, a + m);
bool ans = 1;
for(int i = 0;i < n;i++)
{
f = 0;
solve(0, b[i], 0);
if(!f) ans = 0;
}
cout << (ans ? "YES\n" : "NO\n");
}
# | 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... |