Submission #677326

#TimeUsernameProblemLanguageResultExecution timeMemory
677326sofija6Bank (IZhO14_bank)C++14
100 / 100
100 ms16832 KiB
#include <bits/stdc++.h> #define ll long long #define MAXN (1<<20)+2 using namespace std; ll a[30],b[30]; pair<ll,ll> dp[MAXN]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n,m; cin >> n >> m; for (ll i=1;i<=n;i++) cin >> a[i]; for (ll i=0;i<m;i++) cin >> b[i]; for (ll i=0;i<(1<<m);i++) { if (dp[i].first==n) { cout << "YES\n"; return 0; } for (ll j=0;j<m;j++) { if (((1<<j)&i)!=0) continue; if (dp[i].second+b[j]==a[dp[i].first+1]) { if (dp[i].first+1>=dp[i|(1<<j)].first) dp[i|(1<<j)]={dp[i].first+1,0}; continue; } else if (dp[i].first>=dp[i|(1<<j)].first) dp[i|(1<<j)]={dp[i].first,dp[i].second+b[j]}; } } cout << "NO\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...