题目: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.
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int t=input.nextInt();
while (t-->0) {
int n=input.nextInt();
int arr[]=new int[n];
int s=input.nextInt();
int sum=0,i=0,j=0;
int count=n+1;
for (int a = 0; a < arr.length; a++) {
arr[a]=input.nextInt();
}
while (true) {
while (i<n && sum<s) {
sum+=arr[i++];
}
if (sum<s) {
break;
}
count=Math.min(count, i-j);
sum-=arr[j++];
}
if (count>n) {
count=0;
}
System.out.println(count);
}
// TODO Auto-generated method stub
}
}