Submission #995660

#TimeUsernameProblemLanguageResultExecution timeMemory
995660kokoueBank (IZhO14_bank)C++14
0 / 100
2 ms344 KiB
#include<bits/stdc++.h> #define maxn 21 using namespace std; int n,m; int dp[1<<maxn],sum[1<<maxn],pref[maxn],a[maxn],b[maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>n>>m; for(int i=0;i<n;i++) { cin>>a[i]; if(i!=0) {pref[i]=pref[i-1]+a[i];continue;} pref[i]=a[i]; } for(int i=0;i<m;i++) { cin>>b[i]; } for(int i=1;i<(1<<m);i++) { for(int j=0;j<m;j++) { if(i&(1<<j)) sum[i]+=b[j]; } } for(int i=0;i<(1<<m);i++) { for(int j=0;j<m;j++) { if(!(i&(1<<j))) continue; int k=dp[i^(1<<j)]; int s; if(k==0) s=0; else s=pref[k-1]; if(sum[i]-s==a[k]) dp[i]=max(dp[i],dp[i^(1<<j)]+1); else dp[i]=max(dp[i],dp[i^(1<<j)]); } if(dp[i]==n) {cout<<i<<"\nYES\n";return 0;} } cout<<"NO\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...