Submission #367260

#TimeUsernameProblemLanguageResultExecution timeMemory
367260schiftyfive4Bank (IZhO14_bank)C++14
100 / 100
249 ms94956 KiB
#include <bits/stdc++.h> int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n, m; std::cin >> n >> m; std::vector<int> a(n), pre(n); for (int i = 0; i < n; i++) { std::cin >> a[i]; pre[i] = a[i]; if (i > 0) pre[i] += pre[i - 1]; } std::vector<int> b(m); for (int i = 0; i < m; i++) { std::cin >> b[i]; } std::vector<int> sum(1 << m); for (int mask = 0; mask < (1 << m); mask++) { for (int j = 0; j < m; j++) { if (mask & (1 << j)) sum[mask] += b[j]; } } std::vector<std::vector<int>> dp(n + 1, std::vector<int>(1 << m)); dp[0][0] = 1; for (int i = 0; i <= n; i++) { for (int mask = 0; mask < (1 << m); mask++) { if (dp[i][mask] == 0) continue; if (i == n) { std::cout << "YES\n"; return 0; } for (int j = 0; j < m; j++) { if (!(mask & (1 << j))) { if (sum[mask] + b[j] == pre[i]) dp[i + 1][mask ^ (1 << j)] = 1; if (sum[mask] + b[j] < pre[i]) dp[i][mask ^ (1 << j)] = 1; } } } } std::cout << "NO\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...