#C6515. ATM Withdrawal with Denominations
ATM Withdrawal with Denominations
ATM Withdrawal with Denominations
In this problem, you are given an ATM that contains a total amount (M) and a desired withdrawal amount (W). You are also provided a list of available denominations. The goal is to determine whether it is possible to withdraw exactly (W) using the available denominations. You can use each denomination an unlimited number of times. Note that if (W > M), then it is impossible to withdraw the requested amount. Formally, you need to decide if there exist nonnegative integers (k_1, k_2, \dots, k_n) such that [ W = \sum_{i=1}^{n} k_i \times d_i, ] where (d_i) are the available denominations.
If a valid combination exists, output YES; otherwise, output NO.
inputFormat
The input is read from standard input (stdin) and consists of three lines:
- The first line contains two space-separated integers, (M) (the total amount in the ATM) and (W) (the withdraw amount).
- The second line contains a single integer (n), indicating the number of available denominations.
- The third line contains (n) space-separated integers, representing the available denominations.
outputFormat
Print a single line to standard output (stdout) with either YES if it is possible to withdraw exactly (W) using the given denominations, or NO otherwise.## sample
1000 500
5
100 200 300 400 500
YES