Submission #856182

#TimeUsernameProblemLanguageResultExecution timeMemory
856182ThylOneBank (IZhO14_bank)C++14
71 / 100
1086 ms436 KiB
#include<bits/stdc++.h> using namespace std; int n,m; vector<int> salaries; vector<int> billets; #define BS bitset bool solved(int pos,BS<20> bs){ if(pos==n)return true; vector<int> index; for(int i=0;i<m;i++){ if(!bs[i]){ index.push_back(i); } } const int S = int(index.size()); for(int i=0;i<(1<<S);i++){ BS<20> bs2 = i; int sum=0; for(int j=0;j<S;j++){ if(bs2[j]){ sum+=billets[index[j]]; } if(sum>salaries[pos])break; } if(sum==salaries[pos]){ BS<20> cbs=bs; for(int j=0;j<S;j++){ if(bs2[j]){ cbs[index[j]]=1; } } if(solved(pos+1,cbs)){ return true; } } } return false; } signed main(){ cin>>n>>m; salaries.resize(n); billets.resize(m); for(int i=0;i<n;i++){ cin>>salaries[i]; } for(int i=0;i<m;i++){ cin>>billets[i]; } if(solved(0,0)){ cout<<"YES\n"; }else{ cout<<"NO\n"; } 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...