Submission #596171

#TimeUsernameProblemLanguageResultExecution timeMemory
596171BelphegorBank (IZhO14_bank)C++14
100 / 100
97 ms8516 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; int A[22],B[22]; int LEFT[(1<<20)],dp[(1<<20)]; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n,m; cin>>n>>m; for(int i=1; i<=n; i++) cin>>A[i]; for(int i=0; i<m; i++) cin>>B[i]; for(int i=1; i<(1<<m); i++){ for(int j=0; j<m; j++){ if(!(i&(1<<j))) continue; int sub = i^(1<<j); int cur = dp[sub]+1,money = LEFT[sub]; if(cur<=dp[i]) continue; if(A[cur]==money+B[j]){ dp[i] = cur; LEFT[i] = 0; } else if(dp[sub]>=dp[i]){ dp[i] = dp[sub]; LEFT[i] = LEFT[sub]+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...