Untitled

mail@pastecode.io avatar
unknown
c_cpp
3 years ago
588 B
4
Indexable
Never
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
const int maxn = 100005;
int n;
long long x;
int niza[maxn];

int main()
{
    cin >> n >> x;
    long long sum = 0;
    for(int i = 0; i < n; i++) {
        cin >> niza[i];
    }
    int najdolga = 0;
    int j = 0;
    for(int i = 0; i < n; i++) {
        while(j < n and sum + niza[j] <= x) {
            sum += niza[j];
            j++;
            najdolga = max(najdolga, j - i);
        }
        sum -= niza[i];
    }
    cout << najdolga << endl;
    return 0;
}

/*
 6 50
 12 |13 14 12| 11 11
 
 */