#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll minilength(ll a[], ll n, ll value)
{
ll currentsum = 0, minlength = n+1;
int i = 0, j = 0;
while(j < n)
{
while(currentsum < value && j < n)
currentsum += a[j++];
while(currentsum >= value && i < n)
{
if(j-i < minlength)
minlength = j-i;
currentsum -= a[i++];
}
}
return minlength;
}
int main()
{
ll n, s;
while(cin >> n >> s)
{
ll a[n];
for(int i=0;i<n;i++)
cin >> a[i];
ll mn = minilength(a, n, s);
if(mn == n+1)
cout << 0 << "\n";
else
cout << mn << "\n";
}
return 0;
}
Comments
Post a Comment