Submission #883622

#TimeUsernameProblemLanguageResultExecution timeMemory
883622alexddBank (IZhO14_bank)C++17
100 / 100
116 ms8636 KiB
#include<iostream> using namespace std; int n,m; pair<int,int> dp[1100000]; int a[25]; int b[25]; signed main() { ios_base::sync_with_stdio(0);cin.tie(0); cin>>n>>m; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=0;i<m;i++) cin>>b[i]; dp[0] = {0,0}; for(int config=1;config<(1<<m);config++) { for(int i=0;i<m;i++) { if(((1<<i)&config)) { pair<int,int> cur; int x = dp[config-(1<<i)].first; int y = dp[config-(1<<i)].second; if(a[x+1] == y + b[i]) { dp[config] = max(dp[config], {x+1,0}); } else if(y+b[i] < a[x+1]) { dp[config] = max(dp[config], {x,y+b[i]}); } } } if(dp[config].first==n) { cout<<"YES"; return 0; } } cout<<"NO"; return 0; } ///dp[config] = prefixul maxim care poate fi platit cu bacnotele din config
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...