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 <iostream>
#include <fstream>
using namespace std;
const int nmax=(1<<20)+5;
int s[nmax],cst[nmax],dp[nmax];
int sum[25];
int n,m,i,j,ok,p,b;
int main()
{
//freopen("data.in","r",stdin);
cin>>n>>m;
for(i=1;i<=n;i++)
{
cin>>sum[i];
sum[i]+=sum[i-1];
}
for(i=0;i<m;i++)
{
cin>>cst[(1<<i)];
}
for(i=0;i<(1<<m)&&(!ok);i++)
{
s[i]=s[(i&(i-1))]+cst[((i^(i-1))&i)];
p=i;
while(p)
{
b=((p^(p-1))&p);
dp[i]=max(dp[i],dp[(i^b)]+(s[i]==sum[dp[(i^b)]+1]));
p&=(p-1);
}
if(dp[i]==n)
ok=1;
}
if(ok) 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... |