#K14531. Subset Sum: Achieve the Target Power Level
Subset Sum: Achieve the Target Power Level
Subset Sum: Achieve the Target Power Level
You are given an integer \(N\) representing the number of available power orbs and an integer \(T\) representing the target power level. You are also given a list of \(N\) positive integers where each integer represents the power level of an orb. Your task is to determine whether it is possible to select a subset of these orbs such that the sum of their power levels is exactly \(T\).
In mathematical terms, given a list \(a_1, a_2, \dots, a_N\) and a target \(T\), determine if there exists a subset \(S \subseteq \{1,2,\dots,N\}\) such that \[ \sum_{i \in S} a_i = T \]
If such a subset exists, output Yes
, otherwise output No
.
inputFormat
The first two numbers in the input are the integers \(N\) and \(T\) separated by spaces. The following \(N\) numbers are the power levels of the orbs. All input is provided via standard input (stdin).
For example:
5 9 2 3 7 8 10
outputFormat
Output a single line containing Yes
if it is possible to select a subset of orbs to achieve the target power \(T\); otherwise, output No
. The output should be sent to standard output (stdout).
5 9 2 3 7 8 10
Yes