Submission #630537

#TimeUsernameProblemLanguageResultExecution timeMemory
630537ojoConmigoBank (IZhO14_bank)C++17
71 / 100
1091 ms340 KiB
#include <bits/stdc++.h> using namespace std; int n,m; vector<int> a,b; bool f(int i, int mask){ if(i == n)return true; bool sol = false; for(int newMask = 1; newMask < (1<<m); newMask++){ if((mask&newMask) != 0) continue; int suma = 0; for(int j=0; j<m; j++){ if(newMask&(1<<j)){ suma += b[j]; if(suma > a[i])break; } } if(suma == a[i]){ sol = max(sol,f(i+1,mask|newMask)); if(sol)return true; } } return sol; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m; a.resize(n); b.resize(m); for(int i=0; i<n; i++){ cin >> a[i]; } for(int i=0; i<m; i++){ cin >> b[i]; } if(f(0,0)){ cout << "YES\n"; }else cout << "NO\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...