Problem p02623 (python)

Fixed submission:

import sys
import numpy as np
input = sys.stdin.readline

N, M, K = map(int, input().split())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))


A_list.insert(0, 0)
B_list.insert(0, 0)
A_cumsum = np.cumsum(A_list)
B_cumsum = np.cumsum(B_list)

time = B_cumsum[-1]
ans, j = 0, M



for i in range(N+1):
    if A_cumsum[i] > K:
        break
    while B_cumsum[j] > K - A_cumsum[i]:
        j -= 1
    ans = max(ans, i+j)
print(ans)

Buggy submission (verdict: Runtime Error):

N, M, K = map(int, input().split())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))


A_list.insert(0, 0)
B_list.insert(0, 0)
B_cumsum = np.cumsum(B_list)

time = B_cumsum[-1]
ans, j = 0, M

for i in range(N+1):
    if (time > K):
        break
    while (j > 0 and time > K):
        time -= B_list[j]
        j -= 1

    ans = max(ans, i+j)
    time += A_list[i]

print(ans)

Buggy submission (verdict: Runtime Error):
N, M, K = map(int, input().split())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))


f = open('b20.txt')
data = f.readlines()
data = [d.replace("\n", "").split(" ") for d in data]
N, M, K = map(int, data[0])
A_list = list(map(int, data[1]))
B_list = list(map(int, data[2]))

A_list.insert(0, 0)
B_list.insert(0, 0)
B_cumsum = np.cumsum(B_list)

time = B_cumsum[-1]
ans, j = 0, M

B_list[j]
for i in range(N+1):
    if (time > K):
        break
    while (j > 0 and time > K):
        time -= B_list[j]
        j -= 1
    
    ans = max(ans, i+j)
    time += A_list[i]

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

N, M, K = map(int, input().split())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))

time = 0
A_num = 0
B_num = 0
A_len = len(A_list)
B_len = len(B_list)
while (time <= K) and (A_num != A_len or B_num != B_len):
    if A_num >= A_len:
        B = B_list[B_num]
        time += B
        B_num += 1

    elif B_num >= B_len:
        A = A_list[A_num]
        time += A
        A_num += 1
    else:
        A = A_list[A_num]
        B = B_list[B_num]
        if A < B:
            time += A
            A_num += 1

        elif A > B:
            time += B
            B_num += 1

        else:
            add = 1
            time += A
            while (A_list[A_num + add] == B_list[B_num + add]) and \
                  (time < K):
                time += A_list[A_num + add]
                add += 1
            if A_list[A_num + add] < B_list[B_num + add]:
                A_num += add
            else:
                B_num += add
print(A_num + B_num)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

N, M, K = map(int, input().split())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))

time = 0
A_num = 0
B_num = 0
A_len = len(A_list)
B_len = len(B_list)
while (time <= K) and (A_num != A_len or B_num != B_len):
    if A_num >= A_len:
        B = B_list[B_num]
        time += B
        B_num += 1

    elif B_num >= B_len:
        A = A_list[A_num]
        time += A
        A_num += 1
    else:
        A = A_list[A_num]
        B = B_list[B_num]
        if A < B:
            time += A
            A_num += 1

        elif A > B:
            time += B
            B_num += 1

        else:
            add = 1
            time += A
            while (A_list[A_num + add] == B_list[B_num + add]) and \
                  (time < K):
                time += A_list[A_num + add]
                add += 1
            if A_list[A_num + add] < B_list[B_num + add]:
                A_num += add
            else:
                B_num += add
    print(time)
print(A_num + B_num)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

N, M, K = map(int, input().split())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))

time = 0
A_num = 0
B_num = 0
while (time < K) and (A_num <= len(A_list) -1) and (B_num <= len(B_list) -1):
    A = A_list[A_num]
    B = B_list[B_num]
    if A < B:
        time += A
        A_num += 1

    elif A > B:
        time += B
        B_num += 1

    else:
        add = 1
        time += A
        while (A_list[A_num + add] == B_list[B_num + add]) and \
              (time < K):
            time += A_list[A_num + add]
            add += 1
        if A_list[A_num + add] < B_list[B_num + add]:
            A_num += add
        else:
            B_num += add
print(A_num + B_num - 1)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

N, M, K = map(int, input().split())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))

time = 0
A_num = 0
B_num = 0
while (time < K) and (A_num <= len(A_list) -1) and (B_num <= len(B_list) -1):
    A = A_list[A_num]
    B = B_list[B_num]
    if A < B:
        time += A
        A_num += 1

    elif A > B:
        time += B
        B_num += 1

    else:
        add = 1
        time += A
        while (A_list[A_num + add] == B_list[B_num + add]) and \
              (time < K):
            time += A_list[A_num + add]
            add += 1
        if A_list[A_num + add] < B_list[B_num + add]:
            A_num += add
        else:
            B_num += add
print(A_num + B_num - 1)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

N, M, K = map(int, input().split())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))

time = 0
A_num = 0
B_num = 0
while time < K:
    A = A_list[A_num]
    B = B_list[B_num]
    if A < B:
        time += A
        A_num += 1

    elif A > B:
        time += B
        B_num += 1

    else:
        add = 1
        time += A
        while (A_list[A_num + add] == B_list[B_num + add]) and \
              (time < K):
            time += A_list[A_num + add]
            add += 1
        if A_list[A_num + add] > B_list[B_num + add]:
            A_num += add
        else:
            B_num += add

print(A_num + B_num - 1)