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 = [0]
B = [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())
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 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 a[i] + b[j] > k:
        j -= 1
    ans = max(ans, i + j)
print(ans)

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

Buggy submission (verdict: Runtime Error):
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 i in range(m):
    B.append(B[i]+b[i])
    
ans,j = 0,m
for j 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())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 0
aa = 0
bb = 0
while True:
    if aa >= n and bb >= m:
        break
    elif aa >= n:
        k -= b[bb]
        bb += 1
    elif bb >= m:
        k -= a[aa]
        aa += 1
    else:        
        if a[aa] > b[bb]:
            k -= b[bb]
            bb += 1
        elif a[aa] < b[bb]:
            k -= a[aa]
            aa += 1
        else:
          if a[aa+1] > b[bb+1]:
            k-= b[bb]
            bb += 1
          else:
            k -= a[aa]
            aa += 1
    if k < 0:
      break

if k < 0:
	print(aa+bb-1)
else:
    print(aa+bb)

Buggy 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
while True:
    if len(a) < 1 and len(b) < 1:
        break
    elif len(a) < 1:
        k -= b[0]
        del b[0]
        ans += 1
    elif len(b) < 1:
        k -= a[0]
        del a[0]
        ans += 1
    else:
        if a[0] > b[0]:
            k -= b[0]
            del b[0]
            ans += 1
        elif a[0] < b[0]:
            k -= a[0]
            del a[0]
            ans += 1
        else:
            if a[1] > b[1]:
                k -= b[0]
                del b[0]
                ans += 1
            else:
                k -= a[0]
                del a[0]
                ans += 1
    if k < 0:
        break
if k < 0:
    print(ans-1)
else:
    print(ans)