Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
831 B
3
Indexable
Never

#include <fstream>

using namespace std;

ifstream cin("secvmaxval.in");
ofstream cout("secvmaxval.out");

long long a, n, val, suma[200005];
int bs(int st, int dr, long long x){
    int mij=st+(dr-st)/2;
    //cout<<st<<" "<<dr<<endl;
    if(st>dr){
        return -1;
    }
    if(suma[st]>x){
        return -1;
    }
    if(suma[mij]==x && suma[mij+1]!=x){
        return mij;
    }
    if(suma[mij]<=x){
        return bs(st, mij-1, x);
    }
    if(suma[mij]>x){
        return bs(mij+1, dr, x);
    }
}

int main()
{
   int maxnr=0;
   cin>>n>>val;
   for(int i=1; i<=n; i++){
       cin>>a;
       suma[i]=suma[i-1]+a;
   }
   for(int i=1; i<=n; i++){
    int j=bs(i, n, val+suma[i-1]);
    if(maxnr<j-i+1){
        maxnr=j-i+1;
    }
   }
 cout<<maxnr;


    return 0;
}