Submission #1043896

#TimeUsernameProblemLanguageResultExecution timeMemory
1043896SnowRaven52Bank (IZhO14_bank)C++17
100 / 100
67 ms8792 KiB
#include <bits/stdc++.h> using namespace std; int main(){ // freopen("main.in", "r", stdin); // freopen(".out", "w", stdout); int n, m; cin >> n >> m; int a[n], b[m]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) cin >> b[i]; vector<pair<int,int>> dp((1 << m), make_pair(0, -1)); dp[0].second = a[0]; bool works = false; pair<int, int> p; for (int i = 1; i < (1<<m); i++){ for (int j = 0; j < m; j++){ if(i & (1 << j)){ p = dp[i ^ (1 << j)]; if(p.second < b[j]) continue; p.second -= b[j]; if(p.second == 0){ p.first++; if(p.first == n){ works=true; dp[i]=p; break; } p.second = a[p.first]; } if(p.first >= dp[i].first)dp[i] = p; } } } if(works) cout<<"YES"<<endl; else cout<<"NO"<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...