Submission #443697

#TimeUsernameProblemLanguageResultExecution timeMemory
443697IwanttobreakfreeBank (IZhO14_bank)C++98
100 / 100
100 ms8524 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,-1); vector<int> paid(1<<m,-1); 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]]&&paid[j]>paid[j+(1<<k)]){ extra[j+(1<<k)]=extra[j]+bank[k]; paid[j+(1<<k)]=paid[j]; } else if(extra[j]+bank[k]==sal[paid[j]]&&paid[j]+1>paid[j+(1<<k)]){ 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...