#include<bits/stdc++.h>
using namespace std;
int a[30],b[30];
int arr[(1<<20)],dp[(1<<20)];
int n,m;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
for(int i = 1; i <= n; i++)
{
cin >> a[i];
}
for(int i = 0; i < m; i++)
{
cin >> b[i];
}
for(int i = 1; i < (1 << m);i++)
{
for(int j = 0; j < m; j++)
{
if(!(i & (1 << j)))
{
continue;
}
int msk = i^(1<<j);
int cur = dp[msk]+1;
int cash = arr[msk];
if(cur <= dp[i])
{
continue;
}
if(a[cur] == cash + b[j])
{
dp[i] = cur;
arr[i] = 0;
}
else if(dp[msk] >= dp[i])
{
dp[i] = dp[msk];
arr[i] = arr[msk] + b[j];
}
}
if(dp[i] == n)
{
cout << "YES";
return 0;
}
}
cout << "NO";
}
# | 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... |