N, K = gets.split.map(&:to_i) A = gets.split.map(&:to_i) def dfs(i, e, min, max, sum, memo) if i == e if min == -1 && max == 1 memo[3][sum] = true elsif min == -1 memo[2][sum] = true elsif max == 1 memo[1][sum] = true else memo[0][sum] = true end else dfs(i + 1, e, -1, max, sum - A[i], memo) dfs(i + 1, e, min, max, sum, memo) dfs(i + 1, e, min, 1, sum + A[i], memo) end end memo1 = Hash.new { |h, k| h[k] = {} } memo2 = Hash.new { |h, k| h[k] = {} } mid = N / 2 dfs(0, mid, 0, 0, 0, memo1) dfs(mid, N, 0, 0, 0, memo2) if A.count(K) > 0 puts 'Yes' exit end if memo1[3][K] || memo2[3][K] puts 'Yes' exit end 1.upto(3) do |t| memo1[t].each do |k, v| case t when 1 if memo2[2][K - k] || memo2[3][K - k] puts 'Yes' exit end when 2 if memo2[1][K - k] || memo2[3][K - k] puts 'Yes' exit end when 3 if memo2[1][K - k] || memo2[2][K - k] puts 'Yes' exit end end end end puts 'No'