#C4640. Distribute Books on Shelves

    ID: 48201 Type: Default 1000ms 256MiB

Distribute Books on Shelves

Distribute Books on Shelves

You are given a number of shelves with specific capacities and a total number of books. The task is to determine if it is possible to exactly distribute the books by completely filling some shelves while leaving the others empty. In other words, determine if there exists a subset of shelf capacities whose sum is exactly equal to the total number of books.

For example, if the shelf capacities are [5, 10, 20][5,\ 10,\ 20] and the number of books is 2525, then the answer is (True) because you can fill the shelves with capacities 5 and 20.

inputFormat

The input is read from stdin. The first line contains an integer (n), the number of shelves. The second line contains (n) space-separated integers representing the capacities of the shelves (if (n=0), this line will be empty). The third line contains an integer representing the total number of books.

outputFormat

Output a single line to stdout containing (True) if it is possible to exactly distribute the books by completely filling some shelves, otherwise output (False).## sample

3
5 10 20
25
True