//-----------------(boost)-----------------//
#pragma GCC target ("avx2") //
#pragma GCC optimization ("O3") //
#pragma GCC optimization ("unroll-loops") //
//---------------------------------------- //
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pii pair <int , int>
#define ar3 array <int , 3>
using namespace std;
const int INF = 1e9 + 7;
const int maxn = 2e5 + 7;
int n , m , a[40] , b[40];
bool dp[40][10000];
void solve()
{
cin >> n >> m;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= m; i++) cin >> b[i];
dp[0][0] = 1;
for(int i = 1; i <= n; i++)
{
for(int mask1 = 1; mask1 < (1 << m); mask1++)
{
int mask2 = mask1;
while(mask2 != 0)
{
int sum = 0;
for(int j = 0; j < m; j++)
{
if((mask2 >> j)&1) sum += b[j+1];
}
if(sum == a[i])
{
dp[i][mask1] = max(dp[i][mask1] , dp[i-1][(mask1^mask2)]);
}
mask2 = mask1 & (mask2 - 1);
}
}
}
bool ans = 0;
for(int mask = 0; mask < (1 << m); mask++)
{
ans = max(ans , dp[n][mask]);
}
if(ans) cout << "YES" << '\n';
else cout << "NO" << '\n';
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
solve();
return 0;
}
# | 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... |