Knapsack in a Globalized World
Time limit2sMemory limit512 MB
With unlimited copies of n item sizes, decide whether some multiset sums to exactly k, where k can reach 10^18.
- Level
Medium7 of 10
- Topics
- Number theory, Dynamic programming, Math
- Solved
- No attempts yet
Problem
Globalization has reached even the old and honest trade of burglary. Breaking in somewhere, grabbing whatever you can carry and running off is no longer enough. To stay competitive you have to optimize your profit.
The new rules are:
- rob only enormous stores, where the supply of every item type is effectively unlimited;
- carry an enormous knapsack;
- leave no empty space in the knapsack.
Those rules are hard to follow, so you write a program that decides whether a store is worth robbing.
The store sells types of items, and one item of type takes exactly units of space. You may take any number of items of each type, including none. Decide whether some choice of items fills a knapsack of size exactly, with no space left over.
Input
The first line contains two integers and (, ), the number of item types and the size of your knapsack.
The second line contains integers (), the sizes of the item types.
Output
Print possible if the items can fill the knapsack exactly, and impossible otherwise.