This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define INIT ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
//#define int ll
int n, m, a[21], b[21];
int sum[21];
//bool vm[21][(1ll<<20)-1 ];
vector<int> msk[21];
void complete(int ac, int ind, int pt, int x){
if(x>sum[pt]){
return;
}
if(x==sum[pt]){
msk[pt].pb(ac);
return;
}
if(ind>=20){
return;
}
complete(ac, ind+1, pt, x);
if( (ac&(1ll<<(ind-1)) )==0 ){
complete(ac|(1ll<<(ind-1)), ind+1, pt, x+b[ind]);
}
return;
}
void build(){
msk[0].pb(0);
for(int i=0; i<n; i++){
for(auto ac:msk[i]){
complete(ac, 1, i+1, sum[i]);
}
}
}
int32_t main(){
INIT
cin>>n>>m;
for(int i=1; i<=n; i++){
cin>>a[i];
sum[i]=sum[i-1];
sum[i]+=a[i];
}
for(int i=1; i<=m; i++){
cin>>b[i];
}
build();
/*
cout<<msk[n].size()<<"sz\n";
for(auto c:msk[n]){
cout<<c<<"\n";
}
*/
if(msk[n].size()>0){
cout<<"YES\n";
}
else{
cout<<"NO\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |