Submission #89838

#TimeUsernameProblemLanguageResultExecution timeMemory
89838Bodo171Bank (IZhO14_bank)C++14
100 / 100
107 ms8972 KiB
#include <iostream> #include <fstream> using namespace std; const int nmax=(1<<20)+5; int s[nmax],cst[nmax],dp[nmax]; int sum[25]; int n,m,i,j,ok,p,b; int main() { //freopen("data.in","r",stdin); cin>>n>>m; for(i=1;i<=n;i++) { cin>>sum[i]; sum[i]+=sum[i-1]; } for(i=0;i<m;i++) { cin>>cst[(1<<i)]; } for(i=0;i<(1<<m)&&(!ok);i++) { s[i]=s[(i&(i-1))]+cst[((i^(i-1))&i)]; p=i; while(p) { b=((p^(p-1))&p); dp[i]=max(dp[i],dp[(i^b)]+(s[i]==sum[dp[(i^b)]+1])); p&=(p-1); } if(dp[i]==n) ok=1; } if(ok) cout<<"YES"; else cout<<"NO"; 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...