Submission #593399

#TimeUsernameProblemLanguageResultExecution timeMemory
593399vbeeBank (IZhO14_bank)C++14
19 / 100
167 ms1444 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]; bool f[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]; f[0] = true; for (int mask = 0; mask < MASK(m); mask++) if (f[mask]){ int sum = 0; for (int i = 0; i < m; i++) if (BIT(mask, i)) sum += b[i]; int cur = 0; for (int i = 0; i < n; i++){ if (sum > a[i]) sum -= a[i], cur = i; else break; } for (int i = 0; i < m; i++) if (BIT(mask, i) == 0){ if (sum == 0) f[mask ^ MASK(i)] = true; else if (a[cur] - sum >= b[i]) f[mask ^ MASK(i)] = true; } } for (int mask = 0; mask < MASK(m); mask++) if (f[mask]){ int sum = 0; for (int i = 0; i < m; i++) if (BIT(mask, i)) sum += b[i]; if (sum == totsum) 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...