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 ll int
#define pb push_back
#define fr first
#define sc second
#define N ((ll)(2e5+100))
#define MAX ((ll)(1e16+100))
#define ARRS ((ll)(2e5+100))
#define MOD ((ll)(1e9+7))
#define pb push_back
char dp[22][1060000];
ll a[40];
ll s[2000000];
ll b[40];
ll n,m;
int main(){
cin>>n>>m;
for(int i=0; i<n; i++)
cin>>b[i];
for(int i=1; i<n; i++)
b[i]+=b[i-1];
for(int i=0; i<m; i++)
cin>>a[i];
s[0]=0;
for(int t=0; t<(1<<m); t++)
for(int j=0; j<m; j++)
if(!((t>>j)&1))
s[t|(1<<j)]=s[t]+a[j];
ll pas=0;
dp[0][0]=1;
for(int i=0; i<=n; i++){
for(int t=0; t<(1<<m); t++){
if(!dp[i][t])continue;
if(i==n){
pas=1;
break;
}
if(s[t]==b[i])
dp[i+1][t]=1;
for(int j=0; j<m; j++)
if(!((t>>j)&1))dp[i][t|(1<<j)]=1;
}
}
if(pas)
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... |