Submission #649529

#TimeUsernameProblemLanguageResultExecution timeMemory
649529rsjwBank (IZhO14_bank)C++17
100 / 100
125 ms8560 KiB
#include <bits/stdc++.h> using namespace std; int a[20],b[20],f[1<<20],g[1<<20]; int main() { // freopen("1.in","r",stdin); int n,m,i,j; cin>>n>>m; for(i=0;i<n;i++) cin>>a[i]; for(i=0;i<m;i++) cin>>b[i]; for(i=1;i<(1<<m);i++) { g[i]=1e9; for(j=0;j<m;j++) { if(i&(1<<j)) { if(g[i]<g[i^(1<<j)]+b[j]) continue; g[i]=g[i^(1<<j)]+b[j]; if(g[i]==a[f[i^(1<<j)]]) { f[i]=f[i^(1<<j)]+1,g[i]=0; if(f[i]==n) return printf("YES\n"),0; break; } else f[i]=f[i^(1<<j)]; if(f[i]==n) return printf("YES\n"),0; } } } printf("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...