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;
bool sum[20001];
int n,m;
int a[100],b[100];
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];
}
sum[b[0]]=true;
int maxsum=b[0];
int minsum=b[0];
for(int i=1;i<m;i++)
{
// cout<<"in"<<i<<"\n";
int currmax=0;
for(int j=minsum;j<=maxsum;j++)
{
if(sum[j]==true)
{
if(currmax<j+b[i]) currmax=j+b[i];
// printf("j=%d b[i]=%d\n",j,b[i]);
sum[j+b[i]]=1;
}
}
maxsum=max(maxsum,currmax);
sum[b[i]]=true;
minsum=min(minsum,b[i]);
/*printf("i=%d max=%d min=%d\n",i,maxsum,minsum);
for(int h=0;h<100;h++)
{
printf("%d-%d, ",h,sum[h]);
}
printf("\n");*/
}
/*cout<<"out";
cout<<"maxsum="<<maxsum<<"\n";
for(int i=0;i<=maxsum;i++)
{
if(sum[i]) cout<<i<<" ";
}
cout<<"\n";*/
for(int i=0;i<n;i++)
{
if(!sum[a[i]]) {cout<<"NO\n";return 0;}
}
cout<<"YES\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... |