Submission #1001505

#TimeUsernameProblemLanguageResultExecution timeMemory
1001505ara_araBank (IZhO14_bank)C++17
19 / 100
67 ms16848 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; if(n>m){ cout<<"NO"; return 0; } 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++; 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...