Submission #891677

#TimeUsernameProblemLanguageResultExecution timeMemory
891677ind1vBank (IZhO14_bank)C++11
100 / 100
98 ms8792 KiB
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> a, b; namespace sub4 { bool check() { return n <= 20 && m <= 20; } pair<int, int> f[1 << 20]; void solve() { for (int i = 0; i < (1 << m); i++) { f[i] = {-1, -1}; } f[0] = {0, 0}; for (int msk = 0; msk < (1 << m); msk++) { for (int lst = 0; lst < m; lst++) { if (!(msk >> lst & 1)) { continue; } int prv = msk ^ (1 << lst); if (f[prv].first == -1) { continue; } int pi = f[prv].first; int pj = f[prv].second; if (pj + b[lst] < a[pi]) { f[msk] = {pi, pj + b[lst]}; } else if (pj + b[lst] == a[pi]) { f[msk] = {pi + 1, 0}; } } if (f[msk].first == n) { cout << "YES" << '\n'; return; } } cout << "NO" << '\n'; } } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m; a.resize(n); for (int i = 0; i < n; i++) { cin >> a[i]; } b.resize(m); for (int i = 0; i < m; i++) { cin >> b[i]; } if (sub4::check()) { sub4::solve(); exit(0); } 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...