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.
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
2
10 15
5 1 3 5 10 7 4 9 2 8
5 11
1 2 3 4 5
Sample Output
2
3
#include<iostream>
#include<string.h>
using namespace std;
int n,m,s,test;
int a[101000];///一定开大
int main()
{
cin>>test;
while(test--)
{
cin>>n>>m;
for(int i=1; i<=n; i++)
cin>>a[i];
int ans=0xffff,sum=0,s=1,e=1;///定义前缀和后缀;
while(1)
{///找最小区间,不停;
while(e<=n&&sum<m)///找从1开始到小于m的区间,一直找到最后一位;
///找到比m大的区间和就退出;
sum+=a[e++];///前缀不变,后缀后移,并将值累加到sum中去;
if(sum<m)break;///如果找到终点还是小于m,退出查找,输出0;
ans=min(ans,e-s);///找到了,更新最小区间长度
sum-=a[s++];///前缀移动,开始找最小
}
if(ans==0xffff)ans=0;///ans的值没变,没找到,0;
cout<<ans<<endl;///输出最小区间长度;
}
}