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>
using namespace std;
#define int long long
const int Nmax=1005;
vector<int> v[20*Nmax];
int dp[(1<<21)];
int a[25],b[25];
signed main()
{
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>a[i];
a[i]+=a[i-1];
}
for(int j=0;j<m;j++) cin>>b[j];
dp[0]=-1;
for(int mask=0;mask<(1<<m);mask++)
{
int sum=0;
dp[mask]=-1;
for(int i=0;i<m;i++)
{
if((mask&(1<<i))!=0)
{
dp[mask]=max(dp[mask],dp[mask-(1<<i)]);
sum+=b[i];
}
}
if(sum==a[dp[mask]+1]) dp[mask]++;
}
if(dp[(1<<m)-1]==n) cout<<"YES"<<'\n';
else cout<<"NO"<<'\n';
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... |