82402024-01-13 19:19:32mmatedFolyóparti telkek (40 pont)cpp17Accepted 40/4014ms4344 KiB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf INT_MAX
#define f(i,k,n) for(int i=k; i<n; i++)

void solve()
{
    int n,p;
    cin>>n>>p;
    int x=0, a[n+1];
    a[0]=0;
    f(i,1,n+1)
    {
        cin>>x;
        a[i]=a[i-1]+x;
    }
    int l=0, r=0;
    int maxi=0;
    while(r<=n)
    {
        if(a[r]-a[l]>p) l++;
        if(a[r]-a[l]<=p)
        {
            maxi=max(maxi,r-l);
            r++;
        }
    }
    cout<<maxi<<"\n";
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    //cin>>t;
    while(t--)  solve();
    return 0;
}

SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/03ms2172 KiB
2Accepted0/014ms2992 KiB
3Accepted2/23ms2272 KiB
4Accepted2/23ms2352 KiB
5Accepted2/23ms2480 KiB
6Accepted2/23ms2688 KiB
7Accepted2/23ms2828 KiB
8Accepted3/33ms2912 KiB
9Accepted3/33ms2920 KiB
10Accepted3/33ms3136 KiB
11Accepted3/33ms3132 KiB
12Accepted3/38ms3440 KiB
13Accepted3/38ms3640 KiB
14Accepted3/38ms3924 KiB
15Accepted3/312ms4224 KiB
16Accepted3/312ms4344 KiB
17Accepted3/313ms4300 KiB