Submission #648177

#TimeUsernameProblemLanguageResultExecution timeMemory
648177TS_2392Bank (IZhO14_bank)C++14
100 / 100
71 ms8520 KiB
#include <bits/stdc++.h> #define FAST ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0) #define rall(x) (x).rbegin(), (x).rend() #define all(x) (x).begin(), (x).end() #define sqr(x) (x) * (x) #define epb emplace_back #define lwb lower_bound #define upb upper_bound #define mp make_pair #define fi first #define se second using namespace std; typedef long long ll; typedef long double ldb; typedef unsigned int uint; typedef unsigned long long ull; typedef pair<ll, ll> pll; typedef pair<ll, int> pli; typedef pair<int, ll> pil; typedef pair<int, int> pii; typedef pair<ldb, ldb> pld; typedef pair<double, double> pdd; const int oo = 1e4; int n, m, a[21], b[21]; pii dp[1 << 20]; int main(){ FAST; cin >> n >> m; for(int i = 1; i <= n; ++i) cin >> a[i]; for(int i = 0; i < m; ++i) cin >> b[i]; dp[0] = mp(1, 0); for(int mask = 1; mask < 1 << m; ++mask){ dp[mask].se = oo; for(int i = 0; i < m; ++i) if(mask >> i & 1){ int x = mask ^ 1 << i, idx = dp[x].fi; if(dp[x].se >= oo) continue; if(dp[x].se + b[i] > a[idx]) continue; dp[mask].fi = dp[x].fi; dp[mask].se = dp[x].se + b[i]; if(dp[mask].se == a[idx]){ dp[mask].fi++; dp[mask].se = 0; } break; } if(dp[mask].fi == n + 1 && dp[mask].se == 0){ cout << "YES"; exit(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...