Submission #1131642

#TimeUsernameProblemLanguageResultExecution timeMemory
1131642dr.rabi3Bank (IZhO14_bank)C++20
100 / 100
206 ms164596 KiB
#include <bits/stdc++.h> #define int long long #define el '\n' using namespace std; const int N = 20; int n, m, a[N], b[N], dp[N][1LL << N]; int solve(int i, int mask, int sum_now) { if (i == n) return 1; int &ret = dp[i][mask]; if (~ret) return ret; ret = 0; for (int j = 0; j < m; ++j) { if ((mask >> j) & 1) continue; if (sum_now + b[j] <= a[i]) { if (a[i] == sum_now + b[j]) ret |= solve(i + 1, mask | (1LL << j), 0); else ret |= solve(i, mask | (1LL << j), sum_now + b[j]); } } return ret; } void work() { cin >> n >> m; memset(dp, -1, sizeof dp); for (int i = 0; i < n; ++i)cin >> a[i]; for (int i = 0; i < m; ++i)cin >> b[i]; cout << (solve(0, 0, 0) ? "YES" : "NO") << el; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tc = 1; // cin >> tc; while (tc--) { work(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...