程序代码:
#include <iostream>
using namespace std;
int s[100001],n,f,ans=0;
int main()
{
cin>>n>>f;
for (int i=1; i<=n; i++)
{
cin>>s[i];
s[i]+=s[i-1];
}
for (int i=1,j=0; i<=n; i++)
{
while (s[i]-s[j]>f) j++;
if (ans<i-j) ans=i-j;
}
cout<<ans<<endl;
// system("pause");
}