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<iostream>
#include<bits/stdc++.h>
#define MAXN 1010
using namespace std;
bool dp[MAXN][20010];
int a[MAXN];
int b[MAXN];
int main()
{
int n,m,sum=0;
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>a[i];
sum+=a[i];
dp[i][0]=1;
}
dp[0][0]=1;
for(int i=1;i<=m;i++)
{
cin>>b[i];
}
for(int i=1;i<=m;i++)
{
dp[i][b[i]]=1;
for(int j=1;j<=sum;j++)
{
if(dp[i-1][j])
{
dp[i][j]=1;
dp[i][j+b[i]]=1;
}
}
}
if(dp[m][a[1]])cout<<"YES\n";
else cout<<"NO\n";
}
# | 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... |