Submission #640632

#TimeUsernameProblemLanguageResultExecution timeMemory
640632gnhmhpBank (IZhO14_bank)C++14
100 / 100
111 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; int s=c[x]+b[i]; if (s==a[dp[x]]) dp[mask]=dp[x]+1, c[mask]=0; else if (s<a[dp[x]]) dp[mask]=dp[x], c[mask]=s; } 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...