#C6624. Subset Sum Problem
Subset Sum Problem
Subset Sum Problem
You are given a collection of integers and a target value \(S\). Your task is to determine if there exists a subset of the given collection whose sum equals the target value \(S\). The input consists of multiple test cases.
For each test case, you will be given two numbers \(N\) and \(S\) where \(N\) is the number of elements in the collection and \(S\) is the target sum. Following that, a line containing \(N\) space-separated integers is provided. For each test case, you should output "Possible" if there exists at least one subset of the given numbers whose sum equals \(S\), and "Impossible" otherwise.
Note: Subsets can be empty (and the sum of an empty subset is defined as 0), and the numbers in the array can be negative as well as positive.
inputFormat
The first line of input contains an integer \(T\) representing the number of test cases. The description of the test cases follows.
Each test case consists of two lines:
- The first line contains two integers \(N\) and \(S\), where \(N\) is the number of integers in the collection and \(S\) is the target sum.
- The second line contains \(N\) space-separated integers.
It is guaranteed that \(T \geq 1\) and each test case is well-formed.
outputFormat
For each test case, print a single line containing either "Possible" if there exists a subset whose sum equals \(S\), or "Impossible" if no such subset exists.
## sample3
5 9
1 2 3 4 5
4 0
3 -1 -2 1
3 -5
-2 -3 7
Possible
Possible
Impossible
</p>