Submission #856204

#TimeUsernameProblemLanguageResultExecution timeMemory
856204ThylOneBank (IZhO14_bank)C++14
71 / 100
1042 ms45552 KiB
#include<bits/stdc++.h> using namespace std; int n,m; vector<int> salaries; vector<int> billets; #define BS bitset bool mem[22][(1<<21)]; void initMem(){ for(int i=0;i<22;i++){ for(int j=0;j<(1<<21);j++){ mem[i][j]=false; } } } bool solved(int pos,int act,int curr,int mask){ if(pos==n){ return true; } if(act<0)return false; else if(act==0){ return solved(pos+1,salaries[pos+1],0,mask); } if(curr==m)return false; if(solved(pos,act,curr+1,mask))return true; if(!((mask>>curr)&1) && solved(pos,act-billets[curr],curr+1,mask+(1<<curr))){ return true; } return false; } signed main(){ initMem(); 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]; } sort(billets.begin(),billets.end()); if(solved(0,salaries[0],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...