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_cumsum, B_cumsum = [0], [0]

for i in range(n):
    A_cumsum.append(A_cumsum[i] + A[i])
    
for j in range(m):
    B_cumsum.append(B_cumsum[j] + B[j])
    
ans, j = 0, m

for i in range(n + 1): # 0を最初に代入した分
    if A_cumsum[i] > k:
        break
    while A_cumsum[i] + B_cumsum[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_cumsum, B_cumsum = [0], [0]

for i in range(n):
    A_cumsum.append(A_cumsum[i] + A[i])
    
for j in range(m):
    B_cumsum.append(B_cumsum[j] + B[j])
    
ans = 0

for i, a in enumerate(A_cumsum):
    if a > k:
        break
    
    for j, b in enumerate(B_cumsum):
        if (a + b > k:
            break
        elif (i + j) < ans:
            pass
        else:
            ans = (i + j)

print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np

n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

A.insert(0, 0)
B.insert(0, 0)

A = np.array(A)
B = np.array(B)

A_cumsum = np.cumsum(A)
B_cumsum = np.cumsum(B)

ans = 0

for i, a in enumerate(A_cumsum):
    for j, b in enumerate(B_cumsum):
        n = i + j
        if n > ans:
            if a + b <= k:
                ans = n
            else:
                break

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()))


time = 0
ans = 0
a_next = a.pop(0)
b_next = b.pop(0)

while True:
        
    if a_next <= b_next:
        time += a_next
        try:
            a_next = a.pop(0)
        except:
            a_next = 200001
    
    else:
        time += b_next
        try:
            b_next = b.pop(0)
        except:
            b_next = 200001
    
    if time <= k:
        ans += 1
    else:
        break

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()))


time = 0
ans = 0

while time <= k:
    if a[0] < b[0]:
        time += a.pop(0)
        a.append(200001)
    elif a[0] > b[0]:
        time += b.pop(0)
        b.append(200001)
    else:
        if a[1] < b[1]:
            time += a.pop(0)
            a.append(200001)
        else:
            time += b.pop(0)
            b.append(200001)
    
    if time <= k:
        ans += 1
    else:
        break

print(ans)

Buggy submission (verdict: Runtime Error):
n, m, k = map(int, input().split())
a = [a for a in input().split()]
b = [b for b in input().split()]

time = 0
ans = 0

while time <= k:
    if a[0] < b[0]:
        time += a.pop(0)
        a.append(200001)
    elif a[0] > b[0]:
        time += b.pop(0)
        b.append(200001)
    else:
        if a[1] < b[1]:
            time += a.pop(0)
            a.append(200001)
        else:
            time += b.pop(0)
            b.append(200001)
    
    if time <= k:
        ans += 1
    else:
        break

print(ans)