Problem p02623 (python)

Fixed submission:
if __name__ == '__main__':
    N, M, K = map(int, input().split()) 
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    
    acc_A = []
    acc_B = []
    acc_A.append(0)
    acc_B.append(0)
    
    sum_a = 0
    sum_b = 0

    for a in A:
        sum_a += a
        acc_A.append(sum_a)

    for b in B:
        sum_b += b
        acc_B.append(sum_b)

    large_ar = []
    small_ar = []

    if N > M:
        large_ar = acc_A
        small_ar = acc_B
    else:
        large_ar = acc_B
        small_ar = acc_A
    
    ans = 0
    for i in range(len(small_ar)):
        for j in range(ans-i+1, len(large_ar)):
            if large_ar[j] + small_ar[i] <= K:
                ans = max(ans, i+j)
            else: break
    print(ans)

Buggy submission (verdict: Runtime Error):
if __name__ == '__main__':
    N, M, K = map(int, input().split()) 
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    
    acc_A = []
    acc_B = []
    acc_A.append(0)
    acc_B.append(0)
    
    sum_a = 0
    sum_b = 0

    for a in A:
        sum_a += a
        acc_A.append(sum_a)

    for b in B:
        sum_b += b
        acc_B.append(sum_b)

    large_ar = []
    small_ar = []

    if N > M:
        large_ar = acc_A
        small_ar = acc_B
    else:
        large_ar = acc_B
        small_ar = acc_A
    
    ans = 0
    for i in range(len(large_ar)):
        for j in range(ans - i, len(small_ar)):
            if large_ar[i] + small_ar[j] <= K:
                ans = max(ans, i+j)
            else: break
    print(ans)

Buggy submission (verdict: Runtime Error):
if __name__ == '__main__':
    N, M, K = map(int, input().split()) 
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    
    acc_A = []
    acc_B = []
    acc_A.append(0)
    acc_B.append(0)
    
    sum_a = 0
    sum_b = 0

    for a in A:
        sum_a += a
        acc_A.append(sum_a)

    for b in B:
        sum_b += b
        acc_B.append(sum_b)

    large_ar = []
    small_ar = []

    if N > M:
        large_ar = acc_A
        small_ar = acc_B
    else:
        large_ar = acc_B
        small_ar = acc_A
    
    ans = 0
    for i in range(len(large_ar)):
        for j in range(ans - i, len(small_ar)):
            if large_ar[i] + small_ar[j] <= K:
                ans = max(ans, i+j)
    
    print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque

N, M, K = map(int, input().split())
A = deque(map(int, input().split()))
B = deque(map(int, input().split()))

read_time = 0
read_num = 0

while read_time<=K:
    if len(A)==0 and len(B)==0:
        break
    elif len(A)==0:
        r = B.popleft()
        if K>=read_time+r:
            read_num += 1
            read_time += r
        continue
    elif len(B)==0:
        r = A.popleft()
        if K>=read_time+r:
            read_num += 1
            read_time += r
        continue
    if(A[0]<B[0]):
        r = A.popleft()
        if K>=read_time+r:
            read_num += 1
            read_time += r
    else:
        r = B.popleft()
        if K>=read_time+r:
            read_num += 1
            read_time += r
print(read_num