Submission #800973

#TimeUsernameProblemLanguageResultExecution timeMemory
80097312345678Bank (IZhO14_bank)C++17
100 / 100
119 ms8552 KiB
#include <bits/stdc++.h> using namespace std; int n, m; int main() { cin.tie(NULL)->sync_with_stdio(false); cin>>n>>m; vector<int> a(n), b(m); for (auto &x:a) cin>>x; for (auto &x:b) cin>>x; vector<int> dp(1<<m, -1), l(1<<m, 0); dp[0]=0; for (int i=1; i<(1<<m); i++) { for (int j=0; j<m; j++) { if ((i&(1<<j))==0) continue; if (dp[i-(1<<j)]==-1) continue; if (l[i-(1<<j)]+b[j]==a[dp[i-(1<<j)]]) dp[i]=dp[i-(1<<j)]+1, l[i]=0; else if (l[i-(1<<j)]+b[j]<a[dp[i-(1<<j)]]) dp[i]=dp[i-(1<<j)], l[i]=l[i-(1<<j)]+b[j]; } if (dp[i]==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...