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 st[20],n,m;
vector<int> a,b;
bool sum(int s,int k)
{
if(s == 0)return 1;
if(s < 0)return 0;
for(int i = k;i < m;i++)
{
if(st[i] == 0)
{
st[i] = 1;
if(sum(s - b[i],i+1))return 1;
st[i] = 0;
}
}
return 0;
}
int main()
{
cin>>n>>m;
for(int i = 0;i < m;i++)st[i] = 0;
a.resize(n);b.resize(m);
for(int i = 0;i < n;i++)cin>>a[i];
for(int i = 0;i < m;i++)cin>>b[i];
sort(a.rbegin(),a.rend());
sort(b.rbegin(),b.rend());
for(int i = 0;i < n;i++)
{
if(!sum(a[i],0))
{
cout<<"NO"<<endl;
return 0;
}
}
cout<<"YES"<<endl;
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... |