Submission #443689

#TimeUsernameProblemLanguageResultExecution timeMemory
443689IwanttobreakfreeBank (IZhO14_bank)C++98
19 / 100
116 ms8504 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main(){ int n,m; cin>>n>>m; vector<int> sal(n); vector<int> bank(m); for(int i=0;i<n;i++)cin>>sal[i]; for(int i=0;i<m;i++)cin>>bank[i]; vector<int> extra(1<<m,0); vector<int> paid(1<<m,0); extra[0]=paid[0]=0; for(int j=0;j<(1<<m);j++){ for(int k=0;k<m;k++){ if(j&(1<<k))continue; if(extra[j]+bank[k]<sal[paid[j]]){ extra[j+(1<<k)]=extra[j]+bank[k]; paid[j+(1<<k)]=paid[j]; } else if(extra[j]+bank[k]==sal[paid[j]]){ extra[j+(1<<k)]=0; paid[j+(1<<k)]=paid[j]+1; if(paid[j+(1<<k)]==n){ cout<<"YES"; return 0; } } } } cout<<"NO"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...