Submission #440041

#TimeUsernameProblemLanguageResultExecution timeMemory
440041AutronBank (IZhO14_bank)C++14
100 / 100
136 ms8544 KiB
#include <bits/stdc++.h> using namespace std; int dp[1<<20], lef[1<<20]; int main(){ int n, m; cin>>n>>m; vector<int> a(n), b(m); for(int i=0;i<n;++i){ cin>>a[i]; } for(int i=0;i<m;++i){ cin>>b[i]; } for(int mask=1;mask<(1<<m);++mask){ dp[mask]=-1e9; for(int bit=0;bit<m;++bit){ if(!(mask&(1<<bit))) continue; int pmask=mask^(1<<bit); if(dp[pmask]<0) continue; int val=lef[pmask]+b[bit]; if(val<a[dp[pmask]]){ dp[mask]=dp[pmask]; lef[mask]=val; } else if(val==a[dp[pmask]]){ dp[mask]=dp[pmask]+1; lef[mask]=0; } } if(dp[mask]==n){ cout<<"YES\n"; return 0; } } cout<<"NO\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...