제출 #1136362

#제출 시각아이디문제언어결과실행 시간메모리
1136362classic은행 (IZhO14_bank)C++20
100 / 100
95 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<int> cnt(1 << m, -1), rem(1 << m, -1); cnt[0] = 0; rem[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 (cnt[p] == -1) { continue; } int nxt = rem[p] + b[j]; int need = a[cnt[p]]; if (nxt < need) { cnt[i] = cnt[p]; rem[i] = nxt; } else if (nxt == need) { cnt[i] = cnt[p] + 1; rem[i] = 0; } } if (cnt[i] == 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...