Submission #366737

#TimeUsernameProblemLanguageResultExecution timeMemory
366737schiftyfive4Bank (IZhO14_bank)C++14
100 / 100
231 ms4588 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), b(m), 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]; } for (int i = 0; i < m; i++) { std::cin >> b[i]; } std::vector<int> dp(1 << m); dp[0] = 1; for (int mask = 0; mask < (1 << m); mask++) { if (dp[mask] == 0) continue; int sum = 0; for (int i = 0; i < m; i++) { if (mask & (1 << i)) sum += b[i]; } int idx = 0; while (idx < n && pre[idx] <= sum) ++idx; if (idx == n) { std::cout << "YES\n"; return 0; } for (int i = 0; i < m; i++) { if (!(mask & (1 << i)) && sum + b[i] <= pre[idx]) dp[mask ^ (1 << i)] = 1; } } std::cout << "NO"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...