192972025-12-03 19:33:53birozsFolyóparti telkek (40 pont)pypy3Runtime error 38/4092ms32000 KiB
N,P = map(int,input().split())
telek = list(map(int,input().split()))
bal = 0
while telek[bal] > P and bal < N:
    bal += 1
if bal == N:
    print(0)
else:
    jobb = bal
    maxtelek = 1
    resz = telek[bal]
    while bal < N - maxtelek and jobb < N-1:
        if resz + telek[jobb+1] <= P:
            resz += telek[jobb+1]
            jobb = jobb + 1
        elif telek[jobb+1] >= P:
            bal = jobb + 1
            while bal < N and telek[bal] >= P:
                bal += 1
            if bal < N:
                jobb = bal
                resz = telek[bal]
        elif resz + telek[jobb+1] > P:
            while resz + telek[jobb+1] > P:
                resz -= telek[bal]
                bal += 1
            resz += telek[jobb+1]
            jobb = jobb +1
        if jobb+1-bal > maxtelek:
            maxtelek = jobb+1-bal

print(maxtelek)
    


SubtaskSumTestVerdictTimeMemory
base38/40
1Accepted0/039ms19444 KiB
2Runtime error0/076ms32000 KiB
3Runtime error0/275ms22764 KiB
4Accepted2/239ms19448 KiB
5Accepted2/241ms19428 KiB
6Accepted2/241ms19436 KiB
7Accepted2/246ms19692 KiB
8Accepted3/350ms21472 KiB
9Accepted3/361ms21696 KiB
10Accepted3/365ms21896 KiB
11Accepted3/365ms22232 KiB
12Accepted3/370ms26852 KiB
13Accepted3/372ms28420 KiB
14Accepted3/375ms29240 KiB
15Accepted3/390ms31608 KiB
16Accepted3/392ms31864 KiB
17Accepted3/379ms31892 KiB