Submission #1001498

#TimeUsernameProblemLanguageResultExecution timeMemory
1001498ara_araBank (IZhO14_bank)C++17
19 / 100
71 ms16784 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; } 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++; } } } 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...