All Tracks Algorithms Graphs Breadth First Search Problem

Benny and the Universe
Tag(s):

Medium-Hard

Problem
Editorial
Analytics

Hope you still have not forgotten about pig Benny.

She is asking for help again.

This time you have to answer some queries that Benny will give you.

All actions happen in the Universe where each planet has its own id starting from 0. There are infinite amount of planets.

To travel between different planets there are some special spacecrafts. Each spacecraft is characterized by the number di.

If the id of the planet you are currently staying on is idj and you decided you use spacecraft with di you will go to planet with id equal to idj + di.

Benny's parents live nearby the planet with id equal to 0, so you may assume that there exists some spacecraft for which di is not more than 104.

You have to answer Q queries. Each query consists of one single integer x. You have to answer whether it's possible to go from planet with id equal to 0 to planet with id equal to x.

Constraints

1 <= N <= 10^3

1 <= Q <= 10^5

1 <= Di <= 10^9

1 <= X <= 10^9

Input

The first line contains two integers denoting N and Q.

The second line contains N integers denoting di for spacecrafts. Numbers might be separated with more than one space and not more than 10.

The following Q lines contain single integer denoting xi.

SAMPLE INPUT
3 3
5 6 7
5
10
8
SAMPLE OUTPUT
YES
YES
NO
Explanation

You can reach 5 and 10 (5 + 5) and can not reach 8.

Time Limit: 5.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: C, C++, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Scala 2.11.8, Swift, Visual Basic

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

This Problem was Asked in

HackerEarth

Challenge Name

July Circuits

OTHER PROBLEMS OF THIS CHALLENGE
Notifications
View All Notifications