Submission #669099

#TimeUsernameProblemLanguageResultExecution timeMemory
669099aminBank (IZhO14_bank)C++14
0 / 100
5 ms596 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long n,m; cin>>n>>m; map<long ,long>ma; long a[n]; long b[n]; long ans[1<<m]; vector<long>v; long sum=0; for(long i=0;i<n;i++) { cin>>a[i]; sum+=a[i]; v.push_back(sum); } for(long i=0;i<m;i++) { cin>>b[i]; } for(long i=0;i<(1<<m);i++) { ans[i]=-1; } ans[0]=1; long o=0; long p=0; for(long i=1;i<(1<<m);i++) { o=0; p=0; for(long y=0;y<m;y++) { if(i&(1<<y)) { o+=b[y]; } } // cout<<i<<' '; for(long y=0;y<m;y++) { if(i&(1<<y)) { long u=i-(1<<y); p=o-b[y]; if(ans[u]==-1) { continue; } if(upper_bound(v.begin(),v.end(),o)==upper_bound(v.begin(),v.end(),p)) { ans[i]=1; break; } if(lower_bound(v.begin(),v.end(),o)!=upper_bound(v.begin(),v.end(),o)&&lower_bound(v.begin(),v.end(),o)==upper_bound(v.begin(),v.end(),p)) { ans[i]=1; break; } } } // cout<<o<<' '<<ans[i]<<endl; ma[o]=max(ma[o],ans[i]); } if(ma[sum]==1) { 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...