Submission #331553

#TimeUsernameProblemLanguageResultExecution timeMemory
331553jovan_bBank (IZhO14_bank)C++17
100 / 100
111 ms8684 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; pair <int, int> dp[2000005]; int a[25]; int b[25]; int main(){ ios_base::sync_with_stdio(false), cin.tie(0); cout.precision(10); cout << fixed; int n, m; cin >> n >> m; for(int i=1; i<=n; i++){ cin >> a[i]; } for(int j=0; j<m; j++){ cin >> b[j]; } for(int mask=0; mask<(1<<m); mask++){ if(dp[mask].first == 0 && dp[mask].second == 0 && mask > 0) continue; for(int i=0; i<m; i++){ if((1<<i)&mask) continue; int k = a[dp[mask].first+1] - dp[mask].second; if(k < b[i]) continue; else if(k == b[i]) dp[mask|(1<<i)] = {dp[mask].first+1, 0}; else dp[mask|(1<<i)] = {dp[mask].first, dp[mask].second+b[i]}; } } for(int i=0; i<(1<<m); i++){ if(dp[i].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...