#C2702. Exact Bread Pieces Purchase
Exact Bread Pieces Purchase
Exact Bread Pieces Purchase
You are given a set of bread packs, each containing a specific number of bread pieces. Using any combination of these packs (each pack can be used any number of times), determine if it is possible to purchase exactly m bread pieces.
The problem can be formulated as follows:
Given a list of positive integers, \(a_1, a_2, \dots, a_n\), and a target integer \(m\), decide whether there exists a combination (with repetitions allowed) such that:
[ \sum_{i=1}^{n} c_i a_i = m, \quad c_i \ge 0 ]
If such a combination exists, output "Yes"; otherwise, output "No".
Note: Although the number of bread pack types (n) is provided, you are primarily concerned with the pack sizes and the target number m.
inputFormat
The input is read from standard input (stdin) and is formatted as follows:
- An integer n representing the number of available bread pack types.
- A line with n space-separated integers, each representing the number of bread pieces in a pack.
- An integer m representing the exact number of bread pieces you want to purchase.
Example:
3 2 3 5 11
outputFormat
Output a single line to standard output (stdout):
- If it is possible to purchase exactly m bread pieces using any combination of the available bread packs, output "Yes".
- Otherwise, output "No".
3
2 3 5
11
Yes