Exchanging money
Practice
4 (12 votes)
Greatest common divisor
Algorithms
Gcd
Math
Number theory
Problem
92% Success 2584 Attempts 20 Points 5s Time Limit 256MB Memory 1024 KB Max Code

There are \(N\) types of money denomination in your country having values \(a_1, a_2, ...,a_n\). You went to a shop to buy a product worth \(P\)units, predict whether is it possible to complete the purchase or not (You and the shopkeeper can choose notes of each denomination any number of times). You need to process Q queries for this. Print "YES" if it is possible to complete the purchase, else print "NO".

 

Input Format

  • First line contains two space-separated integers \(N\) and \(Q\)
  • Second line contains n space-separated integers \(a_1, a_2, ...,a_n\)
  • Next \(Q\) lines contains the value of \(P\) for each query.

 

Constraints

\(1 \le N \le 10^5 \)

\(1 \le Q \le 10^5 \)

\(1 \le a_i \le 10^9\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
1 votes
Points:20
1 votes
Tags:
EasyMath
Points:20
Tags:
ImplementationEasy