Submission #979137

#TimeUsernameProblemLanguageResultExecution timeMemory
979137kilkuwuBank (IZhO14_bank)C++17
100 / 100
157 ms4552 KiB
#include <bits/stdc++.h> #define nl '\n' template <typename T> inline bool ckmax(T& x, const T& y) { return x < y ? x = y, 1 : 0; } signed main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int N, M; std::cin >> N >> M; std::vector<int> A(N), B(M); std::vector<int> pref(N + 1); for (int i = 0; i < N; i++) { std::cin >> A[i]; pref[i + 1] = pref[i] + A[i]; } for (int i = 0; i < M; i++) { std::cin >> B[i]; } std::vector<int> dp(1 << M); dp[0] = 0; bool ok = 0; for (int mask = 0; mask < (1 << M); mask++) { int upto = dp[mask]; if (upto == N) { ok = 1; break; } int sum = 0; for (int j = 0; j < M; j++) { if (mask >> j & 1) { sum += B[j]; } } int remain = sum - pref[upto]; for (int j = 0; j < M; j++) { if (mask >> j & 1) continue; ckmax(dp[mask ^ (1 << j)], upto + (remain + B[j] == A[upto])); } } std::cout << (ok ? "YES" : "NO") << nl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...