Problem p02623 (python)

Fixed submission:
N,M,K = list(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 j in range(M):
  b.append(b[j]+B[j])
ans = 0
#print(a,b,N+1)
j = M
for i in range(N+1):
  if a[i] > K:
    break

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

print(ans)

Buggy submission (verdict: Runtime Error):
n,m,l = map(int,input().split(" "))
Ns = input().split(" ")
N = [int (n) for n in Ns]
Ms = input().split(" ")
M = [int(n) for n in Ms]
#print(n,m,l)
#print(N,M)
i = 0
j = 0
total = 0
cnt = 0
while total < l:
  #print(i,j,total,cnt)
  if  i == n and j == m:
    break
  elif i < n and j == m:
    if total + N[i] <= l:
      total = total + N[i]
      i = i+1
      cnt = cnt + 1
    else:
      break
  elif i == n and j < m:
    if total + M[i] <= l:
      total = total + M[j]
      j = j+1
      cnt = cnt +1
    else:
      break
  elif i < n and j < m and (total+N[i] <= l or total+M[j] <= l):
    if N[i] <= M[j]:
      total = total + N[i]
      i = i+1
      cnt = cnt +1
    elif N[i] > M[j]:
      total = total + M[j]
      j = j+1
      cnt = cnt +1
  else:
    break
print(cnt)#,i,j,total,n,m,l)

Buggy submission (verdict: Runtime Error):
n,m,l = map(int,input().split(" "))
Ns = input().split(" ")
N = [int (n) for n in Ns]
Ms = input().split(" ")
M = [int(n) for n in Ms]
#print(n,m,l)
#print(N,M)
i = 0
j = 0
total = 0
cnt = 0
while total <= l:
  #print(i,j,total,cnt)
  if  i == n and j == m:
    break
  elif i < n and j == m:
    if total + N[i] <= l:
      total = total + N[i]
      i = i+1
      cnt = cnt + 1
    else:
      break
  elif i == n and j < m:
    if total + M[i] <= l:
      total = total + M[j]
      j = j+1
      cnt = cnt +1
    else:
      break
  elif i < n and j < m and (total+N[i] <= l or total+M[j] <= l):
    if N[i] <= M[j]:
      total = total + N[i]
      i = i+1
      cnt = cnt +1
    elif N[i] > M[j]:
      total = total + M[j]
      j = j+1
      cnt = cnt +1
  else:
    break
print(cnt)#,i,j,total,n,m,l)

Buggy submission (verdict: Runtime Error):
n,m,l = map(int,input().split(" "))
Ns = input().split(" ")
N = [int (n) for n in Ns]
Ms = input().split(" ")
M = [int(n) for n in Ms]
#print(n,m,l)
#print(N,M)
i = 0
j = 0
total = 0
cnt = 0
while total <= l:
  if  N[i] <= M[j]:
    total = total + N[i]
    i = i+1
    cnt = cnt +1
  else:
    total = total + M[j]
    j = j+1
    cnt = cnt +1
print(cnt-1)

Buggy submission (verdict: Runtime Error):
n,m,l = map(int,input().split(" "))
Ns = input().split(" ")
N = [int (n) for n in Ns]
Ms = input().split(" ")
M = [int(n) for n in Ms]
#print(n,m,l)
#print(N,M)
i = 0
j = 0
total = 0
cnt = 0
while total <= l:
  if  N[i] <= M[j]:
    total = total + N[i]
    i = i+1
    cnt = cnt +1
  else:
    total = total + M[j]
    j = j+1
    cnt = cnt +1
print(cnt)

Buggy submission (verdict: Runtime Error):
n,m,l = map(int,input().split(" "))
Ns = input().split(" ")
N = [int (n) for n in Ns]
Ms = input().split(" ")
M = [int(n) for n in Ms]
#print(n,m,l)
#print(N,M)
i = 0
j = 0
total = 0
cnt = 0
while total <= l:
  if  N[i] <= M[j]:
    total = total + N[i]
    i = i+1
    cnt = cnt +1
  else:
    total = total + M[j]
    j = j+1
    cnt = cnt +1
print(cnt-1)