The Kite
Kostas is getting ready for Clean Monday. He has prepared his kite, but he is missing the tail (the thin string with which he will tie and hold the kite). He doesn't have money to buy a new one from the neighborhood grocery store, but fortunately, the kind grocer gives him an old one that he was going to throw away. However, there is a problem:
- The old tail is not a single piece. It consists of N pieces of string, of different colors, tied together side by side to form a long string.
- Kostas wants to use some of these pieces to make a tail with a length exactly K meters (neither shorter nor longer).
- He doesn't have a knife or scissors and cannot cut the tail at the point that would be convenient for him to achieve his goal.
- He can untie the knots that connect the pieces of the tail, but it requires a lot of effort because they are very tight, and he doesn't want to untie more than two. Also, Kostas is not good at tying knots, so he cannot reattach the pieces he untied.
Considering all these, Kostas thinks that he needs to find some consecutive pieces of the old tail (at the beginning, somewhere in the middle, or at the end) that have a total length exactly K meters. If there are multiple ways to do this, he wants to choose the fewest possible pieces to avoid his friends mocking his colorful tail.
For example, suppose the tail consists of N=6 pieces as follows:
and let's say Kostas wants to make a tail with length K=33 meters. Then, he can choose three pieces, the green, purple, and blue, and have a total length of 20+3+10=33 meters.
Can you help Kostas solve this problem?
Problem
Develop a program in one of the IOI languages (Pascal, C, C++, Java) that, after reading the values of N and K and the lengths of the N pieces of the tail, will print the minimum number of consecutive pieces that have a total length equal to K.
Input Files:
The input files named kite.in are text files with the following structure. They have exactly two lines. The first contains two integers N (1 N 2.000.000) and K (1 K 1.000.000.000) separated by a space: the number of tail pieces and the desired length (in meters). The second line contains exactly N integers Mi separated in pairs by a space (1 Μ 1.000.000, where 1 i N). The integer Μ is the length (in meters) of the i-th piece of the tail. You can assume that the sum of all Μ does not exceed 2.000.000.000.
Output Files:
The output files named kite.out are text files with the following structure. They have exactly one line that contains exactly one integer, the minimum number of consecutive pieces that Kostas can take to have the desired total length. If the problem has no solution, meaning what Kostas wants cannot be done in any way, the only line of the output should contain the number 0 (zero).
Examples of Input - Output Files:
1st
STDIN (kite.in)
6 33
1 4 20 3 10 5
STDOUT (kite.out)
3
Explanation of the first example: This is exactly the example from the previous page.
2nd
STDIN (kite.in)
10 20
3 4 1 6 5 4 12 13 7 8
STDOUT (kite.out)
2
Explanation of the second example: Kostas will prefer two pieces (13+7=20) and not five (4+1+6+5+4=20).
Comments