This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |