279B Codeforces - Books




Solution in c++

#include <iostream>
#include <queue>

using namespace std;

long long n,sum,bst,t,time,tr;

queue<long long int> all;

int main()

{

    cin>>n>>time;

    for(int i=0;i<n;i++){

        cin>>tr;
        all.push(tr);

        sum+=tr;

        while(sum>time){
            sum-=all.front();

            all.pop();

            t--;

        }

        t++;

        bst=max(bst,t);

    }

    cout<<bst;

    return 0;

}

Share on Google Plus

About Mohamed Sobhi

My name is Mo.Sobhy ,I study at School excelling high school in Ain Shams ,Cairo
My hobbies is programming ,and web development ,playing chess and writing horror stories.
    Blogger Comment
    Facebook Comment

0 التعليقات:

إرسال تعليق