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;
int a[22],b[22],n,m;
void cnt(int msk,int in,int sum,int k,int k0)
{
if(in>n)
{
cout<<"YES";
exit(0);
}
if(sum==0)
{
cnt(msk,in+1,a[in+1],0,k0);
return;
}
if(k0<n-in+1)
{
return;
}
for(int i=k+1;i<=m;i++)
{
if(!(msk&(1<<i)) && sum>=b[i])
{
cnt(msk+(1<<i), in,sum-b[i],i,k0-1);
}
}
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
for(int i=1;i<=m;i++)
{
cin>>b[i];
}
//sort(b+1,b+1+m);
cnt(0,1,a[1],0,m);
cout<<"NO";
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... |