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;
int n,m,qs[21],b[21],dp[1<<20];
int main() {
cin>>n>>m;
for(int i=0;i<n;i++)cin>>qs[i],qs[i]+=qs[i-1];
for(int i=0;i<m;i++)cin>>b[i];
for(int mask=1;mask<(1<<m);mask++)
{
int sum=0;
for(int j=0;j<m;j++)if(mask&(1<<j))sum+=b[j];
for(int j=0;j<m;j++)if(mask&(1<<j))dp[mask]=max(dp[mask],dp[mask^(1<<j)]+(qs[dp[mask^(1<<j)]]==sum));
}
if(dp[(1<<m)-1]==n)cout<<"YES";
else 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... |