Buggy python submission (verdict: Runtime Error):
 
a = [0]
b = [0]
for i in range(n):
  a.append(a[i]+A[i])
for j in range(m):
  b.append(b[j]+B[j])
#print(a,b)
 
ans = 0
j = m
for i in range(n+1):
  if a[i] > k:
    break
  while (k - a[i]) < b[j]:
    j -= 1
    if j == -1:
      break
  
  ans = max(ans, i+j)
     
print(ans)

Fixed submission:
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
 
a = [0]
b = [0]
for i in range(n):
  a.append(a[i]+A[i])
for j in range(m):
  b.append(b[j]+B[j])
#print(a,b)
 
ans = 0
j = m
for i in range(n+1):
  if a[i] > k:
    break
  while (k - a[i]) < b[j]:
    j -= 1
    if j == -1:
      break
  
  ans = max(ans, i+j)
     
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a = [0]
b = [0]
for i in range(n):
  a.append(a[i]+A[i])
for j in range(m):
  b.append(b[j]+B[j])
#print(a,b)

ans = 0
for i in range(n+1):
  j = 0
  if a[i] > k:
    break
  while (k - a[i]) >= b[j]:
    j += 1
    if j == m:
      break
  
  if k < (a[i] + b[j]):
      j -= 1
  ans = max(ans, i+j)
     
print(ans)


Fixed submission:
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
 
a = [0]
b = [0]
for i in range(n):
  a.append(a[i]+A[i])
for j in range(m):
  b.append(b[j]+B[j])
#print(a,b)
 
ans = 0
j = m
for i in range(n+1):
  if a[i] > k:
    break
  while (k - a[i]) < b[j]:
    j -= 1
    if j == -1:
      break
  
  ans = max(ans, i+j)
     
print(ans)

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

ans = 0
total = 0
while total <= k:
  if len(a) != 0 and len(b) != 0:
    if a[0] < b[0]:
      total += a.pop(0)
    else:
      total += b.pop(0)
    ans += 1
  elif len(a) == 0:
    total += b.pop(0)
    ans += 1
  elif len(b) == 0:
    total += a.pop(0)
    ans += 1
  else:
    break
if total > k:
  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 = [0]
b = [0]
for i in range(n):
  a.append(a[i]+A[i])
for j in range(m):
  b.append(b[j]+B[j])
#print(a,b)
 
ans = 0
j = m
for i in range(n+1):
  if a[i] > k:
    break
  while (k - a[i]) < b[j]:
    j -= 1
    if j == -1:
      break
  
  ans = max(ans, i+j)
     
print(ans)

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

ans = 0
total = 0
while total <= k:
  if a[0] < b[0]:
    total += a.pop(0)
  else:
    total += b.pop(0)
  ans += 1

if total > k:
  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 = [0]
b = [0]
for i in range(n):
  a.append(a[i]+A[i])
for j in range(m):
  b.append(b[j]+B[j])
#print(a,b)
 
ans = 0
j = m
for i in range(n+1):
  if a[i] > k:
    break
  while (k - a[i]) < b[j]:
    j -= 1
    if j == -1:
      break
  
  ans = max(ans, i+j)
     
print(ans)