제출 #468422

#제출 시각아이디문제언어결과실행 시간메모리
468422four_specks은행 (IZhO14_bank)C++17
100 / 100
135 ms8576 KiB
#include <bits/stdc++.h> using namespace std; void solve() { int n; int m; cin >> n >> m; vector<int> a(n), b(m); for (int i = 0; i < n; i++) cin >> a[i]; for (int j = 0; j < m; j++) cin >> b[j]; bool possible = 0; vector<pair<int, int>> dp(1 << m, pair(-1, 0)); dp[0] = pair(0, 0); for (int mask = 0; mask < 1 << m && !possible; mask++) { for (int j = 0; j < m; j++) { if ((mask >> j) & 1) { auto tr = dp[mask ^ (1 << j)]; if (tr.first != -1) { if (tr.second + b[j] == a[tr.first]) tr.first++, tr.second = 0; else if (tr.second + b[j] < a[tr.first]) tr.second += b[j]; else tr.first = -1, tr.second = 0; dp[mask] = max(dp[mask], tr); } } } possible |= dp[mask].first == n; } cout << (possible ? "YES" : "NO") << '\n'; } int main() { ios_base::sync_with_stdio(false), cin.tie(NULL); solve(); 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...