poj3061

来源:互联网 发布:seo关键字是什么 编辑:程序博客网 时间:2024/06/05 05:31
#include<stdio.h>#include<iostream>using namespace std;#include<algorithm>const int Max=100010;int main(){    int ans;    int n,S,a[Max];    int T;    scanf("%d",&T);//还有这句话我没有太明白其意思,The input will finish with the end of file.,我以为要,while(~scanf("%d",&T)),结果错了        while(T--)        {        int l=0,r=0;        int sum=0;            scanf("%d%d",&n,&S);            for(int i=0; i<n; i++)                scanf("%d",&a[i]);            ans=n+10;/////////////////////这里不能太大,不然就错了            while(true)            {                while(sum<S&&r<n) sum += a[r++];                if(sum < S) break;                ans=min(ans,r-l);                sum = sum-a[l++];            }            if (ans > n) ans = 0;            printf("%d\n",ans);        }    return 0;}