Banana Bunches
시간 제한20초메모리 제한1024 MB
각 값이 K 이하인 음이 아닌 정수 배열에서 합이 정확히 K가 되도록 원소를 골라라. 고른 원소는 최대 두 개의 연속 구간을 이루어야 하며, 개수를 최소로 하라.
문제
Barbara goes to Alan's banana farm, where the banana trees are organized in one 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?
입력
The first line of the input gives the number of test cases, . test cases follow.
Each test case begins with a line containing two integers integer , 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.
출력
For each test case, output one line containing Case #x: y, 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 -1 if it is impossible to do so.
제한
- .
- , for each from to .