Buggy python submission (verdict: Runtime Error):
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

# bを読むのにかかる時間
t = 0

for i in range(m):
    t += b[i]

# bを全部読む
j = m
ans = 0

for i in range(n+1):
    # bで読む本を1冊ずつ諦めていく
    while j > 0 and t > k:
        j -= 1
        t -= b[i]
    
    # 諦められる本すらない場合
    if t > k:
        break

    ans = max(ans, i+j)
    
    # 配列外参照を防ぐ
    if i == n:
        break
    
    # aで読む本を1冊増やす
    t += a[i]

print(ans)




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 = 0
# bを全部読む
j = M

for i in range(N + 1):
    # aは0冊から始まる
    if a[i] > K:
        break

    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
    
    
print(ans)

Buggy python submission (verdict: Runtime Error):
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0
k_list = []

flag = True

if sum(a) + sum(b) <= k:
    flag = False
    print(n+m)

while k > 0:
    if len(a) != 0 and a[0] <= b[0]:
        k -= a.pop(0)
        ans += 1
    else:
        k -= b.pop(0)
        ans += 1


if flag:
    print(ans-1)


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 = 0
# bを全部読む
j = M

for i in range(N + 1):
    # aは0冊から始まる
    if a[i] > K:
        break

    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
    
    
print(ans)

Buggy python submission (verdict: Runtime Error):
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0
k_list = []

flag = True

while k > 0:
    if len(a) > 0 and a[0] <= b[0]:
        k -= a.pop(0)
        ans += 1
    else:
        k -= b.pop(0)
        ans += 1
    if len(a) == 0 and len(b) == 0:
        flag = False
        break

if flag:
    print(ans-1)
else:
    print(ans)

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 = 0
# bを全部読む
j = M

for i in range(N + 1):
    # aは0冊から始まる
    if a[i] > K:
        break

    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
    
    
print(ans)

Buggy python submission (verdict: Runtime Error):
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0
k_list = []

while k > 0:
    ans += 1
    if len(a) > 0 and a[0] <= b[0]:
        k -= a.pop(0)
    else:
        k -= b.pop(0)
    k_list.append(k)

if k_list[-1] < 0:
    print(ans-1)
else:
    print(ans)
        

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 = 0
# bを全部読む
j = M

for i in range(N + 1):
    # aは0冊から始まる
    if a[i] > K:
        break

    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
    
    
print(ans)