Submission #968283

#TimeUsernameProblemLanguageResultExecution timeMemory
968283UmairAhmadMirzaBank (IZhO14_bank)C++17
100 / 100
101 ms11096 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long int const N=21; int const mod=1e9+7; int sal[N]; int coin[N]; int prefix_done[1<<N]; int leftover[1<<N]; int main(){ int n,m; cin>>n>>m; for (int i = 0; i < n; ++i) cin>>sal[i]; for (int i = 0; i < m; ++i) cin>>coin[i]; for (int i = 0; i < (1<<m); ++i){ prefix_done[i]=-1; leftover[i]=-1; } leftover[0]=0; prefix_done[0]=0; for(int mask=0;mask<(1<<m);mask++){ for(int c=0;c<m;c++){ if(((1<<c)&mask)==0) continue; int mk=mask-(1<<c); int lft=leftover[mk]+coin[c]; int man_tar=prefix_done[mk]; if(prefix_done[mk]==-1) continue; if(sal[man_tar]==lft){ prefix_done[mask]=man_tar+1; leftover[mask]=0; } else if(sal[man_tar]>lft){ prefix_done[mask]=man_tar; leftover[mask]=lft; } } // cout<<mask<<' '<<prefix_done[mask]<<' '<<leftover[mask]<<endl; if(prefix_done[mask]==n){ // cout<<mask<<endl; cout<<"YES"<<endl; return 0; } } cout<<"NO"<<endl; 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...