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>
//qwerty47924692
using namespace std;
using ll = int;
#define f first
#define s second
const ll N=3e5+29;
ll n,m,a[N],b[N],ans,p[N],used[N],total[N],have,need;
void f(ll x,ll sum,ll i){
if(x==m){
if(sum==a[i]&&i<n){
need-=a[i];
for(ll i=1;i<=m;i++){
if(used[i]){
total[i]=1;
have-=b[i];
}
}
f(0,0,i+1);
for(ll i=1;i<=m;i++){
if(used[i]){
total[i]=1;
have+=b[i];
}
}
need+=a[i];
}
if(i==n&&sum==a[n]){
ans=1;
// for(ll i=1;i<=m;i++)cout<<used[i]<<' ';
return;
}
return;
}
x++;
if(!total[i])used[x]=1;
if(!total[i]&&sum+b[x]<=a[i]&&need<=have)f(x,sum+b[x],i);
used[x]=0;
f(x,sum,i);
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n>>m;
if(n>m){
cout<<"NO";
return 0;
}
for(ll i=1;i<=n;i++){
cin>>a[i];
need-=a[i];
}
for(ll i=1;i<=m;i++){
cin>>b[i];
have+=b[i];
p[i]=i;
}
f(0,0,1);
cout<<(ans ? "YES" : "NO");
}
# | 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... |