Under construction

Still being built. Things may change

Banana Bunches

Interview

Time limit20sMemory limit1024 MB

Summary
Given tree bunch counts, find the fewest trees to buy so the chosen trees form at most two contiguous blocks summing to exactly K, or -1 if impossible.
Level

Medium5 of 10

Topics
Sliding window, Prefix sum, Array
Solved
No attempts yet

Problem

Barbara visits Alan's banana farm. The NN banana trees stand in one long line, represented by an array BB. The tree at position ii has BiB_i banana bunches. Every tree costs the same. When Barbara buys a tree, she gets all the banana bunches on it. Alan has a special rule: he does not want too many gaps in his line, so Barbara may buy at most 2 contiguous sections of the tree line. Barbara wants the total number of banana bunches on the trees she buys to equal her basket capacity KK. She wants to spend as little money as possible. How many trees should she buy?

Input

The first line contains the number of test cases TT. TT test cases follow.

Each test case begins with a line containing two 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, where the ii-th integer is the number of banana bunches on the ii-th tree.

Output

For each test case, output one line in the form Case #x: y, where xx is the test case number (starting from 1) and yy is the minimum number of trees Barbara must buy to get exactly KK banana bunches using at most 2 contiguous sections of the farm, or -1 if it is impossible.

Constraints

  • 1≤T≤1001 \le T \le 100.
  • 0≤Bi≤K0 \le B_i \le K, for each ii from 1 to NN.

Examples1

  1. Example 1

    Input
    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
    
    Expected output
    Case #1: 3
    Case #2: -1
    Case #3: 4
    Case #4: 3