首页 > 代码库 > LA2678 Subsequence子序列

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;}

 

LA2678 Subsequence子序列