#include <bits/stdc++.h>
using
namespace
std;
int
dp[100001];
int
recur(
int
i,
int
A[],
int
N, vector<
int
>& HashMap,
int
X)
{
if
(i == X) {
return
1;
}
int
ans = 0;
for
(
int
j = 0; j < N; j++) {
if
(i + A[j] <= X and !HashMap[i + A[j]])
ans |= recur(i + A[j], A, N, HashMap, X);
}
return
dp[i] = ans;
}
void
isPossible(
int
A[],
int
B[],
int
N,
int
M,
int
X)
{
memset
(dp, -1,
sizeof
(dp));
vector<
int
> HashMap(100001, 0);
for
(
int
i = 0; i < M; i++) {
HashMap[B[i]] = 1;
}
int
ans = recur(0, A, N, HashMap, X);
if
(ans)
cout <<
"Yes"
<< endl;
else
cout <<
"No"
<< endl;
}
int
main()
{
int
A1[] = { 3, 4, 5 }, B1[] = { 4, 5, 6, 8 }, X1 = 15;
int
N1 =
sizeof
(A1) /
sizeof
(A1[0]);
int
M1 =
sizeof
(B1) /
sizeof
(B1[0]);
isPossible(A1, B1, N1, M1, X1);
int
A2[] = { 2, 3, 4, 5 }, B2[] = { 3, 4, 5, 6 },
X2 = 8;
int
N2 =
sizeof
(A2) /
sizeof
(A2[0]);
int
M2 =
sizeof
(B2) /
sizeof
(B2[0]);
isPossible(A2, B2, N2, M2, X2);
return
0;
}