Submission #630631

#TimeUsernameProblemLanguageResultExecution timeMemory
630631ojoConmigoBank (IZhO14_bank)C++17
71 / 100
1085 ms472 KiB
#include <bits/stdc++.h> using namespace std; #define long long int int n,m; vector<int> a,b; vector<vector<int>> dp; bool f(int i, int mask){ if(i == n)return true; bool sol = false; for(int newMask : dp[i]){ if((mask&newMask) != 0) continue; sol = max(sol,f(i+1,mask|newMask)); if(sol)return true; } return sol; } signed main(){ ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m; a.resize(n); b.resize(m); dp.resize(n); 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<n; i++){ for(int mask = 1; mask < (1<<m); mask++){ int suma = 0; for(int j=0; j<m; j++){ if(mask&(1<<j)){ suma += b[j]; if(suma > a[i])break; } } if(suma == a[i]){ dp[i].push_back(mask); } } } 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...