제출 #864411

#제출 시각아이디문제언어결과실행 시간메모리
864411PM1은행 (IZhO14_bank)C++17
100 / 100
134 ms4828 KiB
#include <bits/stdc++.h> using namespace std; const int mxn=25; int n,m,a[mxn],b[mxn],dp[(1<<20)],ps[mxn]; int main(){ cin>>n>>m; if(n>m){ cout<<"NO"; return 0; } for(int i=1;i<=n;i++){ cin>>a[i]; ps[i]=ps[i-1]+a[i]; } for(int i=1;i<=m;i++){ cin>>b[i]; } for(int mask=1;mask<(1<<m);mask++){ int sum=0; for(int i=0;i<m;i++){ if(mask&(1<<i)){ sum+=b[i+1]; } } for(int i=0;i<m;i++){ if(mask&(1<<i)){ dp[mask]=max(dp[mask],dp[mask-(1<<i)]+(sum==ps[dp[mask-(1<<i)]+1])); } } } if(dp[(1<<m)-1]>=n){ cout<<"YES"<<endl; } else{ cout<<"NO"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...