MANDAR AND BLOCKS
All submissions for this problem are available.
Mandar has N blocks, each block having distinct weight. He has an infinite supply of each of these N blocks. His friend Pratik wants to measure exactly 'k' kilograms so he asks Mandar for the help. Can Mandar make a block weighing exactly 'k' kilograms using any number of blocks he has?
- The first line of the input contains an integer N denoting the number of blocks .
- The second line contains N space-seperated integers Wi denoting the weight of ith block in kilograms.
- The third line of each test case contains Q denoting the number of queries .
- Next Q lines contains an integer k denoting the weight Pratik wants to measure.
For each query print “YES” (without quotes) if it is possible to make a block weighing kkilograms otherwise print ”NO”
- 1 ≤ N ≤ 5000
- 1 ≤ Wi ≤ 50000
- 1 ≤ Q ≤ 5000
- 1 ≤ k ≤ 10^9
4 7 10
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, 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, kotlin, PERL6, TEXT, SCM chicken, CLOJ, COB, FS|
Fetching successful submissions