#C5768. Taco Subset Sum
Taco Subset Sum
Taco Subset Sum
You are given an array of positive integers and a target sum \(T\). Your task is to find any subset of the array whose sum is exactly \(T\). If multiple valid subsets exist, you may output any one of them; if no subset exists, output an empty list.
For example, if the input array is [1, 2, 3, 7] and \(T = 6\), then one correct output is 1 2 3
(representing the subset [1,2,3]).
The solution should read input from stdin and write the result to stdout. In the output, the subset elements must be printed as space-separated integers on a single line. If no valid subset exists, an empty line should be printed.
inputFormat
The input is read from stdin and has the following format:
- The first line contains an integer (n), representing the number of elements in the array.
- The second line contains (n) space-separated positive integers.
- The third line contains a single integer (T), the target sum.
For example:
4 1 2 3 7 6
outputFormat
If a valid subset exists, print the elements of the subset separated by a space on a single line (the order should follow the method used in the solution). If no valid subset exists, print an empty line.## sample
4
1 2 3 7
6
1 2 3
</p>