problems / 195

GCD-Based Resource Distribution

medium gcd number-theory dp 1400 ms · 256 MB

GCD-Based Resource Distribution

A shipping warehouse needs to distribute k identical units among n servers. Server i can only operate on a number of units that is a multiple of d_i (its configuration requirement). For example, if d_i = 3, server i accepts 0, 3, 6, 9, ... units, but rejects 1, 2, 4, 5 units.

You need to check if it's possible to distribute all k units such that every server receives a number of units compatible with its requirement. Each server may receive 0 units (it simply remains idle). The sum of units given to all servers must equal exactly k.

Input

The first line contains n (1 ≤ n ≤ 100) and k (1 ≤ k ≤ 10^6), the number of servers and total units to distribute.

The second line contains n space-separated integers d_1, d_2, ..., d_n (1 ≤ d_i ≤ 1000), the configuration requirement for each server.

Output

Print YES if you can distribute all k units, or NO otherwise.

Notes

This is a variant of the coin change problem: can we make the sum k using non-negative integer multiples of values d_1, d_2, ..., d_n?

Consider the first example: we have 10 units and servers with requirements 2 and 3. One valid distribution is: server 1 gets 4 units (a multiple of 2), server 2 gets 6 units (a multiple of 3), totaling 4 + 6 = 10.

For a NO example, consider 1 unit with requirements 2 and 3. Since 1 is not a multiple of either 2 or 3, we cannot distribute it.

Example 1

Input

2 10
2 3

Output

YES

Example 2

Input

2 5
2 3

Output

YES

Hints · reveal one at a time if you're stuck

Hint 1

With requirements 2 and 3, which small totals can be distributed and which cannot? What does that say about relying on the gcd of the requirements alone?

Hint 2

Build the set of reachable totals from 0 up to k. A total is reachable if subtracting some requirement from it leaves a reachable total.

report an issue Prefer your own editor? sooks prep 195 (CLI)
Sign in to run code

Run your code on the examples, or submit it against every test.