This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#pragma GCC optimize ("unroll-loops")
using namespace std;
int n,m;
int a[22], b[22];
int sum[2000005];
vector<int> fr[1005];
int dp[2][2000005];
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=1;i<=m;i++)
cin>>b[i];
for(int mask=0; mask < (1<<m); mask++)
{
for(int k=0;k<m;k++)
if((mask>>k)&1)
sum[mask] += b[k];
if(sum[mask] <= 1000)
fr[sum[mask]].push_back(mask);
}
for(int mask=0; mask < (1<<m); mask++)
dp[1][mask]=true;
for(int i=1;i<=n;i++)
{
for(int mask = 0; mask<(1<<m); mask++)
{
dp[0][mask] = dp[1][mask];
dp[1][mask] = 0;
}
for(int mask = 0; mask<(1<<m); mask++)
for(int nmask : fr[a[i]])
if((mask | nmask) == mask && dp[0][mask - nmask])
{
dp[1][mask] = true;
break;
}
}
if(dp[1][ (1<<m) - 1 ])
cout<<"YES";
else
cout<<"NO";
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... |