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 N=1<<20;
int dp[21][N],p[30],b[30];
int main(){
int n,m;
cin>>n >>m;
for(int i=0;i<n;i++) cin>>p[i];
for(int i=0;i<m;i++) cin>>b[i];
int lp=1<<m;
for(int i=0;i<n;i++) for(int j=0;j<lp;j++) dp[i][j]=INT_MAX;
dp[0][0]=p[0];
for(int i=0;i<n;i++) for(int j=0;j<lp;j++){
if(dp[i][j]==INT_MAX) continue;
for(int k=0;k<m;k++){
if(j&(1<<k)) continue;
if(dp[i][j]-b[k]>=0) dp[i][j|(1<<k)]=dp[i][j]-b[k];
if(dp[i][j|(1<<k)]==0){
if(i==n-1){
cout<<"YES";
return 0;
}
dp[i+1][j|(1<<k)]=min(dp[i+1][j|(1<<k)],p[i+1]);
}
}
}
/*for(int i=0;i<n;i++){
for(int j=0;j<lp;j++){
cout<<dp[i][j] <<" ";
}
cout<<"\n";
}*/
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... |