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 = 25;
const int MSK = (1 << 20);
int n, m;
int a[N], b[N];
int dp[N][MSK];
int f(int ind, int val, int msk)
{
if (ind == n + 1)
return 1;
if (dp[ind][msk] != -1)
return dp[ind][msk];
int sol = 0;
for (int i = 0; i < m; i++)
if (!(msk & (1 << i)) && b[i] <= val)
{
if (b[i] < val)
sol = max(sol, f(ind, val - b[i], msk + (1 << i)));
else
sol = max(sol, f(ind + 1, a[ind + 1], msk + (1 << i)));
}
dp[ind][msk] = sol;
return sol;
}
int main()
{
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 0; i < m; i++)
cin >> b[i];
for (int i = 1; i <= n; i++)
for (int j = 0; j < (1 << m); j++)
dp[i][j] = -1;
if (f(1, a[1], 0))
cout << "YES";
else
cout << "NO";
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... |