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;
const int mxn=25;
int n,m,a[mxn],b[mxn],dp[(1<<20)],ps[mxn];
int main(){
cin>>n>>m;
if(n>m){
cout<<"NO";
return 0;
}
for(int i=1;i<=n;i++){
cin>>a[i];
ps[i]=ps[i-1]+a[i];
}
for(int i=1;i<=m;i++){
cin>>b[i];
}
for(int mask=1;mask<(1<<m);mask++){
int sum=0;
for(int i=0;i<m;i++){
if(mask&(1<<i)){
sum+=b[i+1];
}
}
for(int i=0;i<m;i++){
if(mask&(1<<i)){
dp[mask]=max(dp[mask],dp[mask-(1<<i)]+(sum==ps[dp[mask-(1<<i)]+1]));
}
}
}
if(dp[(1<<m)-1]>=n){
cout<<"YES"<<endl;
}
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... |