Submission #963591

#TimeUsernameProblemLanguageResultExecution timeMemory
963591maxFedorchukBank (IZhO14_bank)C++17
100 / 100
179 ms756 KiB
#include<bits/stdc++.h> using namespace std; int a[22],b[22],n,m; void dfs(int x,int sum,int state,int k,int num) { int i; if(x>n) { cout<<"YES"; exit(0); } if(sum==0) { dfs(x+1,a[x+1],state,0,num); return; } for(i=k+1;i<=m;i++) { if(m-num-1<n-x) break; if(state&(1<<i) || sum<b[i]) continue; dfs(x,sum-b[i],state+(1<<i),i,num+1); } } int main() { cin>>n>>m; for(int i=1;i<=n;i++) { cin>>a[i]; } for(int i=1;i<=m;i++) { cin>>b[i]; } dfs(1,a[1],0,0,0); 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...