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>
#pragma GCC target("avx2,sse4,popcnt,bmi")
#pragma GCC optimize("Ofast,unroll-loops")
using namespace std;
const long long MX=22;
int a[MX],b[MX];
int n,m;
void cnt(int msk,int in,int zalsum,int munin,int k0)
{
if(in>n)
{
cout<<"YES\n";
exit(0);
}
if(zalsum==0)
{
cnt(msk,in+1,a[in+1],0,k0);
return;
}
if(k0<(n-in+1))
{
return;
}
for(int i=munin+1;i<=m;i++)
{
if(!((msk>>i)&1))
{
if(zalsum>=b[i])
{
cnt(msk|(1<<i),in,zalsum-b[i],i,k0-1);
}
}
}
}
int main()
{
cin.tie(0);
ios_base::sync_with_stdio(0);
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
for(int i=1;i<=m;i++)
{
cin>>b[i];
}
cnt(0,1,a[1],0,m);
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... |