#P16863. [GKS 2021 #G] Banana Bunches

[GKS 2021 #G] Banana Bunches

Problem Description

Barbara goes to Alan's banana farm, where the NN banana trees are organized in 11 long line represented by an array BB. The tree at position ii has BiB_i 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 22 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 KK of her basket. She wants to do this while spending as little money as possible. How many trees should she buy?

Input Format

The 11st line of the input gives the number of test cases, TT. TT test cases follow.

Each test case begins with a line containing 22 integers: NN, the number of trees on Alan's farm, and KK, the capacity of Barbara's basket.

The next line contains NN non-negative integers B1,B2,,BNB_1, B_2, \ldots, B_N representing array BB, where the ii-th integer represents the number of banana bunches on the ii-th tree on Alan's farm.

Output Format

For each test case, output 11 line containing Case #xx: yy, where xx is the test case number (starting from 11) and yy is the minimum number of trees Barbara must purchase to obtain KK banana bunches using at most 22 contiguous sections of the farm, or 1-1 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 #11, the first section can contain the trees at indices 22 and 33, and the second section can contain the tree at index 66.

In Sample Case #22, it is impossible to achieve a sum of 1010 with 22 contiguous sections.

In Sample Case #33, the first section can contain the trees at indices {1,2}\{1, 2\}, and the second section can contain the trees at indices {5,6}\{5, 6\}. We cannot take the 2+3+32 + 3 + 3 combo (trees at indices {1,3,5}\{1, 3, 5\}) since that would be 33 contiguous sections.

In Sample Case #44, the only section contains the trees at indices {1,2,3}\{1, 2, 3\}.

Limits

1T1001 \le T \le 100.

0BiK0 \le B_i \le K, for each ii from 11 to NN.

Test Set 11

1K1041 \le K \le 10^4.

1N501 \le N \le 50.

Test Set 22

1K1041 \le K \le 10^4.

1N5001 \le N \le 500.

Test Set 33

1K1061 \le K \le 10^6.

For at most 2525 cases:

1N50001 \le N \le 5000.

For the remaining cases:

1N5001 \le N \le 500.