Subsequence
time limit per test 1 second memory limit per test 256 megabytes
A sequence of N positive integers (10 < N < 100 000), each of them less than or equal 10000, and a positive integer S (S < 100 000 000) are given. Write a program to find the minimal length of the subsequence of consecutive elements of the sequence, the sum of which is greater than or equal to S.

传送门:POJ3061

Input

The first line is the number of test cases. For each test case the program has to read the numbers N and S, separated by an interval, from the first line. The numbers of the sequence are given in the second line of the test case, separated by intervals. The input will finish with the end of file.

Output

For each the case the program has to print the result on separate line of the output file.if no answer, print 0.

Sample Input

1
2
3
4
5
2
10 15
5 1 3 5 10 7 4 9 2 8
5 11
1 2 3 4 5

Sample Output

1
2
2
3

题解

比赛时候不会尺取 学习一波
## AC code:(不包含输入类)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import java.io.*;  
import java.util.*;
public class Main {

public static void main(String[] args) {
FastScanner sc=new FastScanner();
PrintWriter pw=new PrintWriter(System.out);
int t=sc.nextInt();
while(sc.hasNext()){
int n=sc.nextInt();
int m=sc.nextInt();
int[]shu=new int[n];
for(int i=0;i<n;i++)shu[i]=sc.nextInt();
int i=0;
int j=0;
int sum=0;
int res=Integer.MAX_VALUE;
while(true){
while(j<n&&sum<=m){
sum+=shu[j];
j++;
}
if(sum<m)break;
res=Math.min(res, j-i);
sum-=shu[i];
i++;
}
if(res==Integer.MAX_VALUE)res=0;
pw.println(res);
pw.flush();
}

}
}