Problem p02623 (python)

Fixed submission:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)

Buggy submission (verdict: Runtime Error):
n, m, k = map(int, input().split())
arA = list(map(int, input().split()))
arB = list(map(int, input().split()))

idxA = idxB = 0
readTime :int = 0
readBooks :int = 0

"""
while readTime < k:
    #if arA[idxA] <= arB[idxB] and idxA < n:
    if idxA < n and arA[idxA] <= arB[idxB]:
        if k < readTime + arA[idxA]:
            break
        readTime += arA[idxA]
        idxA += 1
    else:
        if k < readTime + arB[idxB]:
            break
        readTime += arB[idxB]
        idxB += 1
    readBooks += 1
    if idxA >= n and idxB >= m:
        break
"""

while readTime < k:
    if idxA < n and arA[idxA] <= arB[idxB]:
        readTime += arA[idxA]
        idxA += 1
    else:
        readTime += arB[idxB]
        idxB += 1

    if readTime <= k:
        readBooks += 1
    else:
        break
    if idxA >= n and idxB >= m:
        break

print(readBooks)

Buggy submission (verdict: Runtime Error):
n, m, k = map(int, input().split())
arA = list(map(int, input().split()))
arB = list(map(int, input().split()))

idxA = idxB = 0
readTime :int = 0
readBooks :int = 0
while readTime < k:
    #if arA[idxA] <= arB[idxB] and idxA < n:
    if idxA < n and arA[idxA] <= arB[idxB]:
        if k < readTime + arA[idxA]:
            break
        readTime += arA[idxA]
        idxA += 1
    else:
        if k < readTime + arB[idxB]:
            break
        readTime += arB[idxB]
        idxB += 1
    readBooks += 1
    if idxA >= n and idxB >= m:
        break

print(readBooks)

Buggy submission (verdict: Runtime Error):
n, m, k = map(int, input().split())
arA = list(map(int, input().split()))
arB = list(map(int, input().split()))

idxA = idxB = 0
readTime :int = 0
readBooks :int = 0
while readTime < k:
    #if arA[idxA] <= arA[idxB] and idxA < n:
    if idxA < n and arA[idxA] <= arA[idxB]:
        if k < readTime + arA[idxA]:
            break
        readTime += arA[idxA]
        idxA += 1
    else:
        if k < readTime + arB[idxB]:
            break
        readTime += arB[idxB]
        idxB += 1
    readBooks += 1
    if idxA >= n and idxB >= m:
        break

print(readBooks)

Buggy submission (verdict: Runtime Error):
n, m, k = map(int, input().split())
arA = list(map(int, input().split()))
arB = list(map(int, input().split()))

idxA = idxB = 0
readTime :int = 0
readBooks :int = 0
while readTime < k:
    if arA[idxA] <= arA[idxB] and idxA < n:
        if k < readTime + arA[idxA]:
            break
        readTime += arA[idxA]
        idxA += 1
    else:
        if k < readTime + arB[idxB]:
            break
        readTime += arB[idxB]
        idxB += 1
    readBooks += 1
    if idxA >= n and idxB >= m:
        break

print(readBooks)

Buggy submission (verdict: Runtime Error):
n, m, k = map(int, input().split())
arA = list(map(int, input().split()))
arB = list(map(int, input().split()))

idxA = idxB = 0
readTime :int = 0
readBooks :int = 0
while readTime < k:
    if arA[idxA] <= arA[idxB] and idxA < n:
        readTime += arA[idxA]
        idxA += 1
    else:
        readTime += arB[idxB]
        idxB += 1
    readBooks += 1
    if idxA >= n and idxB >= m:
        break

print(readBooks)