首页 > 代码库 > Codeforces 279B Books

Codeforces 279B Books

#include<bits/stdc++.h>
using namespace std;
int a[100020];
int main()
{
    int n,t;
    scanf("%d%d",&n,&t);
    int sum=0,k=1,Max=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        sum+=a[i];
        while(sum>t)
        {
            sum-=a[k];
            k++;
        }
        if(i-k+1>Max)
            Max=i-k+1;
    }
    printf("%d\n",Max);
    return 0;
}

Codeforces 279B Books