Submission #1065779

#TimeUsernameProblemLanguageResultExecution timeMemory
1065779CrabCNHBank (IZhO14_bank)C++17
100 / 100
106 ms8636 KiB
#include <bits/stdc++.h> using namespace std; #define pii pair <int, int> #define fi first #define se second const int N = 22; const int inf = 1e9 + 7; pii f[(1 << N) + 1]; int a[N], b[N]; int n, m; bool bit(int x, int i) { return ((x >> i) & 1); } int flip (int x, int i) { return (x ^ (1 << i)); } int main () { ios_base :: 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]; } for (int mask = 0; mask < (1 << m); mask ++) { for (int i = 0; i <=m; i ++) { if (bit (mask, i)) { pii cur = f[flip (mask, i)]; if (cur.se + b[i] < a[cur.fi]) { f[mask] = max (f[mask], {cur.fi, cur.se + b[i]}); } else if (cur.se + b[i] == a[cur.fi]){ f[mask] = max (f[mask], {cur.fi + 1, 0}); } } } if (f[mask].fi == 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...