Submission #734108

#TimeUsernameProblemLanguageResultExecution timeMemory
734108benjaminkleynBank (IZhO14_bank)C++17
71 / 100
1088 ms8240 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n, m, a[20], b[20]; vector<int> masks[20001]; bool search(int i, int cur_mask) { if (i == n) return true; for (const int &mask : masks[a[i]]) if ((cur_mask & mask) == 0 && search(i + 1, cur_mask | mask)) return true; return false; } int main() { cin.tie(0)->sync_with_stdio(0); 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 mask = 0; mask < (1 << m); mask++) { int sum = 0; for (int i = 0; i < m; i++) if (mask & (1 << i)) sum += b[i]; masks[sum].push_back(mask); } cout << (search(0, 0) ? "YES\n" : "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...