Submission #1105543

#TimeUsernameProblemLanguageResultExecution timeMemory
1105543NewtonabcBank (IZhO14_bank)C++14
100 / 100
171 ms82512 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...