#K62402. Taco Subset Spiciness Challenge
Taco Subset Spiciness Challenge
Taco Subset Spiciness Challenge
You are given a list of dishes, where each dish has an associated spiciness level represented by an integer. Your task is to determine whether there exists a subset of dishes such that the sum of their spiciness levels is exactly equal to a given desired sum.
Formally, if you are given a list \(a_1, a_2, \dots, a_n\) and a target integer \(T\), determine if there exists a subset \(S \subseteq \{1, 2, \dots, n\}\) such that \[ \sum_{i \in S} a_i = T. \]
Input is given via standard input and output should be printed to standard output.
inputFormat
The first line contains an integer \(n\) representing the number of dishes.
The second line contains \(n\) space-separated integers, representing the spiciness levels of the dishes.
The third line contains an integer \(T\), the desired spiciness level.
outputFormat
Output a single line with YES
if there exists a subset of dishes with spiciness levels summing exactly to \(T\), otherwise output NO
.
4
1 3 2 5
8
YES
</p>