#K59312. Taco Challenge: Subset Sum Dish Preparation

    ID: 30837 Type: Default 1000ms 256MiB

Taco Challenge: Subset Sum Dish Preparation

Taco Challenge: Subset Sum Dish Preparation

You are given a target calorie count c and a list of ingredients, where each ingredient has a specified calorie value. Your task is to determine whether there exists a subset of these ingredients whose total calorie sum is exactly c. In mathematical terms, you need to check if there exists a subset S such that:

\( \sum_{i \in S} a_i = c \)

If c = 0, the answer is always True since an empty subset produces 0 calories.

This is a classic dynamic programming problem known as the Subset Sum problem.

inputFormat

The input is given via stdin in the following format:

<c> <n>
<a1> <a2> ... <an>

Here, c is an integer representing the target calorie count, n is the number of ingredients, and the following n integers represent the calorie values of the ingredients.

outputFormat

Output a single line via stdout containing either True if it is possible to achieve the exact calorie count using some subset of the ingredients, or False otherwise.

## sample
8 6
3 34 4 12 5 2
True

</p>