Submission #76745

#TimeUsernameProblemLanguageResultExecution timeMemory
76745szawinisBank (IZhO14_bank)C++17
71 / 100
1073 ms740 KiB
#include <bits/stdc++.h> using namespace std; int n, m, a[20], b[20]; int curr[20]; bool solve(int idx, int mask) { if(n - __builtin_popcount(mask) > m - idx) return false; if(mask == (1 << n) - 1) return true; if(solve(idx + 1, mask)) return true; for(int i = 0; i < n; i++) if(!(mask >> i & 1)) { bool res = false; curr[i] += b[idx]; if(curr[i] == a[i]) res |= solve(idx + 1, mask | 1 << i); else res |= solve(idx + 1, mask); curr[i] -= b[idx]; if(res) return true; } return false; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m; for(int i = 0; i < n; i++) cin >> a[i]; for(int i = 0; i < m; i++) cin >> b[i]; if(solve(0, 0)) cout << "YES" << endl; else cout << "NO" << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...