LA2678 Subsequence子序列

    感觉还不错又简单的的一个题

    

#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 100005;
const int INF = 0x3f3f3f3f;
int a[maxn];
int main()
{
//    freopen("in.txt","r",stdin);
    int n,s;
    while(~scanf("%d%d",&n,&s))
    {
        int sum = 0,ans = INF,p = 1;
        for(int i = 1;i<=n;++i)
        {
            scanf("%d",a+i);
            sum+=a[i];
            while(sum>=s)
            {
                if(sum-a[p]<s)break;
                sum-=a[p++];
                ans = min(ans,i-p+1);
            }
        }
        if(ans>=INF)ans = 0;
        printf("%d\n",ans);
    }
    return 0;
}

 

posted on 2015-01-22 12:11  round_0  阅读(100)  评论(0编辑  收藏  举报

导航