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;
const int MAX=20;
int plata[MAX],pari[MAX];
bool flag=false;
void f(int i,int cnt[])
{
if(i>=m)
{
for(int j=0; j<n; j++)if(plata[j]!=cnt[j])return;
flag=true;
return;
}
for(int j=0; j<n; j++)
{
if(cnt[j]+pari[i]<=plata[j])
{
cnt[j]+=pari[i];
f(i+1,cnt);
cnt[j]-=pari[i];
}
//cout<<"add: "<<pari[i]<<" on pos: "<<j+1<<endl;
f(i+1,cnt);
}
}
int main()
{
cin>>n>>m;
for(int i=0; i<n; i++)cin>>plata[i];
sort(plata,plata+n);
for(int i=0; i<m; i++)cin>>pari[i];
int cnt[n];
memset(cnt,0,sizeof(cnt));
f(0,cnt);
if(flag)cout<<"YES"<<endl;
else cout<<"NO"<<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... |