Submission #594168

#TimeUsernameProblemLanguageResultExecution timeMemory
594168leroycutBank (IZhO14_bank)C++17
100 / 100
79 ms8552 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const int N = 100003, mod = 1e9 + 7, inf = 1e9 + 7; int n, m; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("movie.in", "r", stdin); // freopen("movie.out", "w", stdout); cin >> n >> m; vector<int> vn(n), vm(m), last((1 << m)), dp((1 << m), -1); for(int i = 0; i < n; ++i){ cin >> vn[i]; } for(int j = 0; j < m; ++j){ cin >> vm[j]; } dp[0] = 0; last[0] = 0; for(int s = 1; s < (1 << m); ++s){ for(int i = 0; i < m; ++i){ if((s & (1 << i))){ int prev = s - (1 << i); if(dp[prev] == n){ dp[s] = n; break; } if(dp[prev] == -1) continue; if(last[prev] + vm[i] < vn[dp[prev]]){ dp[s] = dp[prev]; last[s] = last[prev] + vm[i]; break; } if(last[prev] + vm[i] == vn[dp[prev]]){ dp[s] = dp[prev] + 1; last[s] = 0; // cout << prev << " lox\n"; break; } } } // cout << dp[s] << " " << last[s] << "\n"; } if(dp[(1 << m) - 1] == n){ cout << "YES"; } else{ cout << "NO"; } // cout << dp[(1 << m) - 1]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...