Submission #502454

#TimeUsernameProblemLanguageResultExecution timeMemory
502454clamsBank (IZhO14_bank)C++17
100 / 100
107 ms16728 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int N = 20; int n, m, a[N + 5], b[N + 5]; int lef[(1 << N) + 5]; int done[(1 << N) + 5]; signed main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) cin >> b[i]; memset(lef, -1, sizeof lef); memset(done, -1, sizeof done); lef[0] = 0; done[0] = 0; for (int s = 0; s < (1 << m); s++) { for (int i = 0; i < m; i++) { if ((s >> i) & 1) { int t = s ^ (1 << i); if (done[t] == -1) continue; int x = lef[t] + b[i]; int need = a[done[t]]; if (x < need) { done[s] = done[t]; lef[s] = x; } else if (x == need) { done[s] = done[t] + 1; lef[s] = 0; } } } if (done[s] == n) { cout << "YES"; return 0; } } 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...