Submission #1001641

#TimeUsernameProblemLanguageResultExecution timeMemory
1001641ara_araBank (IZhO14_bank)C++17
100 / 100
81 ms17092 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int maxn=(1<<20); int n,m,a[21],b[21]; pair<int,int> dp[maxn]; signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 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 mask=0;mask<(1<<m);mask++){ if(dp[mask].first==n){ cout<<"YES"; return 0; } if(dp[mask].first==0 && dp[mask].second==0 && mask!=0) continue; for(int i=0;i<m;i++){ if((mask>>i & 1)==0){ int nxt=mask^(1<<i); if(dp[mask].second+b[i]>a[dp[mask].first]) continue; dp[nxt].second=dp[mask].second+b[i]; dp[nxt].first=dp[mask].first; if(dp[nxt].second==a[dp[nxt].first]){ dp[nxt].first++; dp[nxt].second=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...