Untitled

 avatar
unknown
c_cpp
4 years ago
588 B
6
Indexable
#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
 
 */
Editor is loading...