Submission #734102

#TimeUsernameProblemLanguageResultExecution timeMemory
734102benjaminkleynBank (IZhO14_bank)C++17
71 / 100
1094 ms8148 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 (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); } for (int sum = 0; sum <= 20000; sum++) sort(masks[sum].begin(), masks[sum].end(), [] (const int &x, const int &y) {return __builtin_popcount(x) < __builtin_popcount(y);}); 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...