59582023-10-06 13:56:39mmatedLeghosszabb nyaralás (75 pont)cpp17Accepted 75/7514ms5720 KiB
#include <bits/stdc++.h>
using namespace std;
#define f(i,k,n) for(int i=k; i<n; i++)
#define ll long long
const int inf = INT_MAX;

void solve()
{
    int n,m;
    cin>>n>>m;
    int p[n+1];
    p[0]=0;
    int x;
    cin>>x;
    p[1]=x;
    f(i,2,n+1)
    {
        cin>>x;
        p[i]=p[i-1]+x;
    }
    if(p[n]<=m)
    {
        cout<<n;
        return;
    }
    vector<int> a;
    int kezd=0, veg=1;

    while(kezd<=veg && veg<n+1)
    {
        if(p[veg]-p[kezd]<=m)
        {
            a.push_back(veg-kezd);
            veg++;
        }
        else
        {
            kezd++;
        }
    }
    int maxi=0;
    for(auto q: a) if(maxi<q)   maxi=q;
    cout<<maxi;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t=1;
    //cin>>t;
    while(t--)  solve();
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base75/75
1Accepted0/03ms1832 KiB
2Accepted0/014ms4092 KiB
3Accepted3/32ms2108 KiB
4Accepted3/33ms2228 KiB
5Accepted3/33ms2588 KiB
6Accepted3/32ms2572 KiB
7Accepted3/33ms2704 KiB
8Accepted4/43ms2888 KiB
9Accepted4/43ms3028 KiB
10Accepted5/53ms3248 KiB
11Accepted5/54ms3844 KiB
12Accepted5/54ms3924 KiB
13Accepted7/79ms4552 KiB
14Accepted7/712ms5644 KiB
15Accepted7/713ms5640 KiB
16Accepted8/813ms5720 KiB
17Accepted8/813ms5704 KiB