Sums
Time limit1sMemory limit128 MB
Given a set A of positive integers and queries b, decide for each b whether it can be written as an unlimited sum of elements of A.
- Level
Hard8 of 10
- Topics
- Number theory, Dynamic programming, Greedy
- Solved
- No attempts yet
Problem
You are given a set of positive integers. Consider the set of non-negative integers where a number belongs to if and only if can be written as a sum of some elements of (each element may be used any number of times, including zero times).
For example, if , then contains (the empty sum), , () and ( or ), while and do not belong to .
Given the description of the set and a sequence of integers , write a program that decides, for each , whether it belongs to .
Input
The first line contains the number of elements of the set (). Each of the next lines contains one element of : the -th line holds a positive integer (), with , so that .
The -th line contains the number of queries (). Each of the next lines contains one integer with .
Output
Print lines. The -th line must contain TAK (Polish for 'yes') if belongs to , and NIE (Polish for 'no') otherwise.