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>
#define ll long long
using namespace std;
ll dp[45][45][2501],a[45],b[45];
int main()
{
ll n,m,i,j,g;
cin>>n>>m;
for(i=1;i<=n;i++)
cin>>a[i];
for(i=1;i<=m;i++)
cin>>b[i];
dp[0][0][0]=1;
for(i=1;i<=m;i++)
for(j=0;j<=n;j++)
{
for(g=0;g<=a[j];g++)
{
dp[i][j][g]=dp[i-1][j][g];
if (g==b[i]) dp[i][j][g]=max(dp[i][j][g],dp[i-1][j-1][a[j-1]]);
if (g>b[i])dp[i][j][g]=max(dp[i][j][g],dp[i-1][j][g-b[i]]);
}
}
if (dp[m][n][a[n]])
cout<<"Yes";
else cout<<"No";
}
# | 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... |