#P6394. Collecting Sakura Blossoms
Collecting Sakura Blossoms
Collecting Sakura Blossoms
You are given k cherry trees, where under the i-th tree you can collect at most \(s_i\) blossoms (collecting 0 is allowed). You need to collect exactly \(n\) blossoms in total. However, there is a twist: as you move from the first tree to the k-th tree, if at the end of any tree the total number of collected blossoms equals \(n\), you may immediately announce your success. Even if you have reached \(n\) before the last tree, you may choose to continue collecting cherries (but note that after reaching \(n\), you can only pick 0 in subsequent trees to avoid exceeding \(n\)). Each announcement time (i.e. the tree after finishing which you choose to announce your collection of exactly \(n\) blossoms) is considered a distinct plan.
Compute the total number of distinct plans which allow you to collect exactly \(n\) blossoms. If it is impossible to collect exactly \(n\) blossoms (i.e. there is no way to achieve the sum even if you collect from all trees), output impossible
.
inputFormat
The first line contains two integers \(n\) and \(k\) \( (0 \leq n \leq \text{some bound},\, 1 \leq k \leq \text{some bound})\), representing the exact number of blossoms to collect and the number of cherry trees, respectively.
The second line contains \(k\) integers: \(s_1, s_2, \dots, s_k\), where \(0 \leq s_i\) indicates the maximum number of blossoms that can be collected from the i-th tree.
outputFormat
Output a single line containing the total number of distinct plans. If it is impossible to collect exactly \(n\) blossoms, output impossible
.
sample
3 3
1 2 3
7