#K95827. Subset Sum Possibility
Subset Sum Possibility
Subset Sum Possibility
You are given n villagers each possessing a certain number of gold coins, along with a dragon that demands exactly k coins. Your task is to determine whether it is possible to select a subset of villagers such that the sum of their coins is exactly k.
Formally, given a list of integers \(a_1, a_2, \dots, a_n\) representing the number of coins each villager has, determine if there exists a subset \(S\) such that:
\(\sum_{i \in S} a_i = k\)
If such a subset exists, output "Possible"; otherwise, output "Impossible".
inputFormat
The input consists of three lines:
- The first line contains a single integer n, denoting the number of villagers.
- The second line contains n space-separated integers, where each integer represents the number of gold coins that a villager has.
- The third line contains a single integer k, the exact number of coins required by the dragon.
outputFormat
Output a single line containing either "Possible" if there exists a subset that sums to exactly k or "Impossible" if no such subset exists.
## sample5
3 34 4 12 5
9
Possible
</p>