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>
using namespace std;
#define ll long long
const ll MAXN=21;
ll n,m;
ll a[MAXN],b[MAXN];
bool f[MAXN][1<<MAXN];
ll sumb[1<<MAXN],pa[MAXN];
int main(){
ll i,j;
cin>>n>>m;
for(i=0;i<n;i++)
cin>>a[i];
for(i=0;i<m;i++)
cin>>b[i];
pa[0]=a[0];
for(i=1;i<n;i++)
pa[i]=pa[i-1]+a[i];
for(i=0;i<(1<<m);i++){
for(j=0;j<m;j++){
if(i&(1<<j)){
sumb[i]+=b[j];
}
}
}
f[0][0]=1;
for(i=0;i<n;i++){
for(j=0;j<(1<<m);j++){
if(f[i][j]){
for(ll c=0;c<m;c++){
if(!(j&(1<<c)) && sumb[j]+b[c]<=pa[i]){
f[i][j|(1<<c)]=1;
if(sumb[j]+b[c]==pa[i]){
f[i+1][j|(1<<c)]=1;
}
}
}
}
}
}
for(i=0;i<(1<<m);i++){
if(f[n][i]){
cout<<"YES\n";
return 0;
}
}
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... |