Submission #333021

#TimeUsernameProblemLanguageResultExecution timeMemory
333021nandonathanielBank (IZhO14_bank)C++14
71 / 100
834 ms262148 KiB
#include<bits/stdc++.h> using namespace std; vector<int> v[1005]; vector<int> valid[20]; int a[20],b[20]; int main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int n,m; cin >> n >> m; for(int i=0;i<n;i++)cin >> a[i]; for(int i=0;i<m;i++)cin >> b[i]; for(int i=0;i<(1<<m);i++){ int uang=0; for(int j=0;j<m;j++){ if((1<<j) & i)uang+=b[j]; } if(uang>1000)continue; v[uang].push_back(i); } if(v[a[0]].empty()){ cout << "NO\n"; return 0; } valid[0]=v[a[0]]; for(int i=1;i<n;i++){ if(v[a[i]].empty()){ cout << "NO\n"; return 0; } vector<int> bisa; for(auto isi : valid[i-1]){ for(auto isi2 : v[a[i]]){ if((isi&isi2)==0)valid[i].push_back(isi+isi2); } } if(valid[i].empty())break; } if(valid[n-1].empty())cout << "NO\n"; else cout << "YES\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...