Chef and Numbers
All submissions for this problem are available.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
You are given some integers in the range between 1 and N. You have to answer Q queries, each query is given by number X, you have to tell whether you can write number X as a sum of allowed numbers. You can use an allowed integer zero or multiple times.
The first line contains three integer numbers N and K, Q, where K denotes number of allowed integers, Q denotes number of queries. The second line containing K distinct integers Fi - allowed numbers.
Each of the next Q lines containing one integer number X.
For each query output "Yes" or "No" (without quotess) in separate line.
- 1 ≤ N, K, Q, X ≤ 200,000
- 1 ≤ Fi ≤ N
Input: 4 2 3 2 4 2 8 5 Output: Yes Yes No
Example case 1. 2 = 2
Example case 2. 8 = 2 + 2 + 4
Example case 3. 5 can't be sum of any number of addends 2 and 4
|Tags||cook77, fft, medium, mgch|
|Time Limit:||1.5 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.5, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.