Submission #677322

#TimeUsernameProblemLanguageResultExecution timeMemory
677322sofija6Bank (IZhO14_bank)C++14
19 / 100
75 ms16696 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++) { for (ll j=0;j<m;j++) { if (((1<<j)&i)!=0) continue; if (dp[i].second+b[j]==a[dp[i].first+1]) dp[i|(1<<j)]={dp[i].first+1,0}; else dp[i|(1<<j)]={dp[i].first,dp[i].second+b[j]}; if (dp[i|(1<<j)].first==n) { cout << "YES\n"; return 0; } } } 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...