Submission #640628

#TimeUsernameProblemLanguageResultExecution timeMemory
640628gnhmhpBank (IZhO14_bank)C++14
19 / 100
86 ms8532 KiB
#define taskname "bank." #include <bits/stdc++.h> #define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr); using namespace std; int n, m; int a[20], b[20], dp[1<<20], c[1<<20]; int main() { fastio; 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 i=1; i<(1<<m); ++i) dp[i]=c[i]=-1; for (int mask=1; mask<(1<<m); ++mask) { for (int i=0; i<m; ++i) { if (!(mask&(1<<i))) continue; int x=mask^(1<<i); if (dp[x]==-1) continue; c[mask]=c[x]+b[i]; if (c[mask]==a[dp[x]]) dp[mask]=dp[x]+1, c[mask]=0; else if (c[mask]<a[dp[x]]) dp[mask]=dp[x]; } if (dp[mask]==n) { cout << "YES"; return 0; } } cout << "NO"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...