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 n,m;
int a[30],b[30];
bool try_sum(int sum,int idx)
{
if(sum==0) return true;
if(sum<0) return false;
for(int i=idx+1;i<m;i++)
{
if(try_sum(sum-b[idx],i)) return true;
if(try_sum(sum,i)) return true;
}
return false;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n>>m;
for(int i=0;i<n;i++)
{
cin>>a[i];
}
for(int i=0;i<m;i++)
{
cin>>b[i];
}
// sort(b,b+n);
for(int i=0;i<n;i++)
{
if(try_sum(a[i],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... |