#C1369. Subset Sum Determination
Subset Sum Determination
Subset Sum Determination
You are given a set of N cards, each with an integer value. Your task is to determine whether there exists a subset of these cards whose sum is exactly \( M \).
This problem can be efficiently solved using dynamic programming. One of the recurrences you can use is:
\( dp[j] = dp[j] \lor dp[j - value] \)
where dp[j] is true if a subset with sum j can be formed using the available cards.
If a subset exists that sums to \( M \), print "Possible"; otherwise, print "Impossible".
inputFormat
The first line of input contains two integers N and M, where N is the number of cards and M is the target sum.
The second line contains N space-separated integers representing the values on the cards.
Example:
5 9 1 2 3 4 5
outputFormat
Output a single line containing "Possible" if there is a subset whose sum exactly equals M, otherwise print "Impossible".
Example:
Possible## sample
5 9
1 2 3 4 5
Possible