Submission #1136367

#TimeUsernameProblemLanguageResultExecution timeMemory
1136367classicBank (IZhO14_bank)C++20
100 / 100
97 ms8520 KiB
// mode: short code /* practicing.. */ #include<bits/stdc++.h> int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); int n, m; std::cin >> n >> m; std::vector<int> a(n); for (int i = 0; i < n; i++) { std::cin >> a[i]; } std::vector<int> b(m); for (int i = 0; i < m; i++) { std::cin >> b[i]; } std::vector<std::pair<int, int>> dp(1 << m, {-1, -1}); dp[0] = {0, 0}; for (int i = 1; i < (1 << m); i++) { for (int j = 0; j < m; j++) { if (!(i & (1 << j))) { continue; } int p = (i ^ (1 << j)); if (dp[p].first == -1) { continue; } if (dp[p].second + b[j] == a[dp[p].first]) { dp[i] = std::max(dp[i], {dp[p].first + 1, 0}); } else { dp[i] = std::max(dp[i], {dp[p].first, dp[p].second + b[j]}); } } if (dp[i].first == n) { std::cout << "YES"; return 0; } } std::cout << "NO"; 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...