Submission #594173

#TimeUsernameProblemLanguageResultExecution timeMemory
594173vbeeBank (IZhO14_bank)C++14
100 / 100
86 ms8592 KiB
#include <bits/stdc++.h> #define fi first #define se second #define all(r) (r).begin(), (r).end() #define MASK(i) (1 << (i)) #define BIT(x, i) ((x) >> (i) & 1) #define ll long long #define pb push_back #define TASK "task" using namespace std; template <typename T1, typename T2> bool minimize(T1 &a, T2 b){ if (a > b) {a = b; return true;} return false;} template <typename T1, typename T2> bool maximize(T1 &a, T2 b){if (a < b) {a = b; return true;} return false;} const int oo = 1e9 + 7; const ll loo = (ll)1e18 + 7; const int LOG = 18; const int BASE = 323; const int N = 20; int n, m, a[N], b[N]; int f[MASK(N)], leftover[MASK(N)]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); // freopen(TASK".inp", "r", stdin); // freopen(TASK".out", "w", stdout); cin >> n >> m; int totsum = 0; for (int i = 0; i < n; i++) cin >> a[i], totsum += a[i]; for (int i = 0; i < m; i++) cin >> b[i]; memset(f, -1, sizeof f); memset(leftover, -1, sizeof leftover); f[0] = 0, leftover[0] = 0; for (int mask = 0; mask < MASK(m); mask++) if (f[mask] != -1) { for (int i = 0; i < m; i++) if (!BIT(mask, i)){ int amt = leftover[mask] + b[i]; int cur = a[f[mask]]; if (amt < cur){ leftover[mask ^ MASK(i)] = amt; f[mask ^ MASK(i)] = f[mask]; } else if (amt == cur){ f[mask ^ MASK(i)] = f[mask] + 1; leftover[mask ^ MASK(i)] = 0; } if (f[mask ^ MASK(i)] == n) return cout << "YES\n", 0; } } cout << "NO\n"; 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...