using System;
using System.Linq;
public class Program{
static int[,] dp = new int[101, 100001];
// Copy code
static void memset(int[,] dp, int x)
{
for (int i = 0; i < dp.GetLength(0); i++)
{
for (int j = 0; j < dp.GetLength(1); j++)
dp[i, j] = -1;
}
}
// Recursive function to tell whether target
// sum is possible or not
static int recur(int i, int j, int target, int[] arr1, int[] arr2, int N)
{
// Base case
if (i == N)
{
// Return 1 if total sum
// is equal to target
if (j == target)
return 1;
else
return 0;
}
// If current state is precomputed then
// just return already computed value
if (dp[i, j] != -1)
return dp[i, j];
int ans = 0;
// Recursive call for adding
// arr1[i] in sum
if (j + arr1[i] <= target)
ans = recur(i + 1, j + arr1[i], target, arr1, arr2, N);
// Recursive call for adding
// arr2[i] in sum
if (j + arr2[i] <= target)
ans = Math.Max(ans, recur(i + 1, j + arr2[i], target, arr1, arr2, N));
// Save and return dp value
return dp[i, j] = ans;
}
// Function to Check whether
// target sum possible or not
static void isNewArrayPossible(int[] arr1, int[] arr2, int N, int target)
{
// Filling dp table with -1
memset(dp, -1);
// If recur function returns one then
// it is possible else it is not
if (recur(0, 0, target, arr1, arr2, N) == 1)
Console.WriteLine("Yes");
else
Console.WriteLine("No");
}
static void Main(string[] args)
{
// Input 1
int[] arr1 = { 3, 4 };
int[] arr2 = { 6, 5 };
int N = arr1.Length;
int M = 10;
// Function Call
isNewArrayPossible(arr1, arr2, N, M);
// // Input 2
int[] arr3 = { 10, 10 };
int[] arr4 = { 100, 100 };
int N1 = arr3.Length;
int M1 = 90;
// // Function call
isNewArrayPossible(arr3, arr4, N1, M1);
// // Input 3
int[] arr5 = { 1, 5, 3, 2 };
int[] arr6 = { 8, 7, 4, 6 };
int N2 = arr5.Length;
int M2 = 12;
isNewArrayPossible(arr5, arr6, N2, M2);
}
}