Submission #1108920

#TimeUsernameProblemLanguageResultExecution timeMemory
1108920julia_08Bank (IZhO14_bank)C++17
100 / 100
113 ms8956 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 22; int a[MAXN], b[MAXN]; pair<int, int> dp[1 << MAXN]; // maximo prefixo, quanto ja paguei int main(){ cin.tie(0)->sync_with_stdio(0); int n, m; 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 s=0; s<(1 << m); s++) dp[s] = {-1, 0}; for(int s=0; s<(1 << m); s++){ for(int i=0; i<m; i++){ if(s & (1 << i)) continue; dp[s ^ (1 << i)] = max(dp[s ^ (1 << i)], dp[s]); if(a[dp[s].first + 1] - dp[s].second == b[i]){ dp[s ^ (1 << i)] = max(dp[s ^ (1 << i)], {min(n - 1, dp[s].first + 1), 0}); } else if(b[i] < a[dp[s].first + 1] - dp[s].second){ dp[s ^ (1 << i)] = max(dp[s ^ (1 << i)], {dp[s].first, dp[s].second + b[i]}); } } // cout << s << " " << dp[s].first << " " << dp[s].second << "\n"; } cout << ((dp[(1 << m) - 1].first == n - 1) ? "YES" : "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...