#K53207. Coin Change Sum Match

    ID: 29480 Type: Default 1000ms 256MiB

Coin Change Sum Match

Coin Change Sum Match

You are given a target sum \(T\) and a list of coin denominations. You have an unlimited supply of each coin. Your task is to determine whether it is possible to form the target sum \(T\) using any number of coins (including using the same coin multiple times).

More formally, given a target integer \(T\) and a list of \(n\) coin values \(c_1, c_2, \ldots, c_n\), determine if there exists a sequence \(a_1, a_2, \ldots, a_k\) (\(k \ge 0\)) such that:

\(a_1 + a_2 + \cdots + a_k = T\)

where each \(a_i\) is one of the coin values. Note that if \(T = 0\), the answer is always "Matched" (since choosing no coins yields a sum of 0).

If it is possible to form the sum, print Matched; otherwise, print Not Matched.

inputFormat

The input is read from standard input and consists of two lines:

  • The first line contains two integers: T (the target sum) and n (the number of coins).
  • The second line contains n space-separated integers representing the coin denominations.

outputFormat

Output a single line to standard output containing either Matched if the target can be formed using any combination (with unlimited repetition allowed) of the given coin denominations, or Not Matched if it cannot.

## sample
7 5
1 2 3 4 5
Matched