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;
const int N=110;
int n,m;
int a[N],b[N];
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];
vector<int> left(1<<m,-1);
vector<int> cover(1<<m,-1);
left[0]=0;
cover[0]=0;
for(int s=0;s<(1<<m);s++)
{
for(int last=1;last<=m;last++)
{
if((s&(1<<last))==0) continue;
int prev=s&~(1<<last);
if(cover[prev]==-1) continue;
int newamt=left[prev]+b[last];
int curt=a[cover[prev]];
if(newamt<curt)
{
cover[s]=cover[prev];
left[s]=newamt;
}
else if(newamt==curt)
{
cover[s]=cover[prev]+1;
left[s]=0;
}
if(cover[s]==n)
{
cout<<"YES";
}
else cout<<"NO";
return 0;
}
}
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... |