#P16863. [GKS 2021 #G] Banana Bunches
[GKS 2021 #G] Banana Bunches
Problem Description
Barbara goes to Alan's banana farm, where the banana trees are organized in long line represented by an array . The tree at position has banana bunches. Each tree has the same cost. Once Barbara buys a tree, she gets all the banana bunches on that tree.
Alan has a special rule: because he does not want too many gaps in his line, he allows Barbara to buy at most contiguous sections of his banana tree line.
Barbara wants to buy some number of trees such that the total number of banana bunches on these purchased trees equals the capacity of her basket. She wants to do this while spending as little money as possible. How many trees should she buy?
Input Format
The st line of the input gives the number of test cases, . test cases follow.
Each test case begins with a line containing integers: , the number of trees on Alan's farm, and , the capacity of Barbara's basket.
The next line contains non-negative integers representing array , where the -th integer represents the number of banana bunches on the -th tree on Alan's farm.
Output Format
For each test case, output line containing Case #: , where is the test case number (starting from ) and is the minimum number of trees Barbara must purchase to obtain banana bunches using at most contiguous sections of the farm, or if it is impossible to do so.
4
6 8
1 2 3 1 2 3
4 10
6 7 5 2
6 8
3 1 2 1 3 1
4 6
3 1 2 0
Case #1: 3
Case #2: -1
Case #3: 4
Case #4: 3
Hint
In Sample Case #, the first section can contain the trees at indices and , and the second section can contain the tree at index .
In Sample Case #, it is impossible to achieve a sum of with contiguous sections.
In Sample Case #, the first section can contain the trees at indices , and the second section can contain the trees at indices . We cannot take the combo (trees at indices ) since that would be contiguous sections.
In Sample Case #, the only section contains the trees at indices .
Limits
.
, for each from to .
Test Set
.
.
Test Set
.
.
Test Set
.
For at most cases:
.
For the remaining cases:
.