Buggy python submission (verdict: Time Limit Exceeded):
import bisect

def main():
    N, M, K = map(int, input().split())
    A = [int(v) for v in input().split()]
    B = [int(v) for v in input().split()]
    if N < M:
        for _ in range(M-N):
            A.append(0)
    else:
        for _ in range(N-M):
            B.append(0)
    C = [v1+v2 for v1, v2 in zip(A, B)]
    ruisekiA = [0 for _ in range(len(C)+1)]
    ruisekiB = [0 for _ in range(len(C)+1)]
    ruisekiC = [0 for _ in range(len(C)+1)]
    for i in range(len(C)):
        ruisekiA[i + 1] = ruisekiA[i] + A[i]
        ruisekiB[i + 1] = ruisekiB[i] + B[i]
        ruisekiC[i + 1] = ruisekiC[i] + C[i]

    ans = 0
    # i番目までは両方読む
    for i in range(min(N, M)+1):
        tans = i * 2
        tk = K - ruisekiC[i]
        if tk < 0:
            continue

        # A だけ、Bだけで何冊読めるか考える
        idx_a = bisect.bisect_left(ruisekiA[:N+1], tk + ruisekiA[i])
        if idx_a == len(ruisekiA) or ruisekiA[idx_a] != tk + ruisekiA[i]:
            idx_a -= 1
        idx_b = bisect.bisect_left(ruisekiB[:M+1], tk + ruisekiB[i])
        if idx_b == len(ruisekiB) or ruisekiB[idx_b] != tk + ruisekiB[i]:
            idx_b -= 1
        ans = max(ans, max(tans+idx_a-i, tans+idx_b-i))
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
import bisect


def main():
    N, M, K = map(int, input().split())
    A = [int(v) for v in input().split()]
    B = [int(v) for v in input().split()]
    ruisekiA = [0 for _ in range(N+1)]
    ruisekiB = [0 for _ in range(M+1)]
    for i in range(N):
        ruisekiA[i + 1] = ruisekiA[i] + A[i]
    for i in range(M):
        ruisekiB[i + 1] = ruisekiB[i] + B[i]

    ans = 0
    # A を i 個 使う
    for i in range(N+1):
        tans = i
        tk = K - ruisekiA[i]
        if tk < 0:
            break
        idx = bisect.bisect_left(ruisekiB, tk)
        if M+1 == idx or ruisekiB[idx] != tk:
            idx -= 1
        tans += idx
        ans = max(ans, tans)
    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import bisect

def main():
    N, M, K = map(int, input().split())
    A = [int(v) for v in input().split()]
    B = [int(v) for v in input().split()]
    if N < M:
        for _ in range(M-N):
            A.append(0)
    else:
        for _ in range(N-M):
            B.append(0)
    C = [v1+v2 for v1, v2 in zip(A, B)]
    ruisekiA = [0 for _ in range(len(C)+1)]
    ruisekiB = [0 for _ in range(len(C)+1)]
    ruisekiC = [0 for _ in range(len(C)+1)]
    for i in range(len(C)):
        ruisekiA[i + 1] = ruisekiA[i] + A[i]
        ruisekiB[i + 1] = ruisekiB[i] + B[i]
        ruisekiC[i + 1] = ruisekiC[i] + C[i]

    ans = 0
    # i番目までは両方読む
    for i in range(min(N, M)+1):
        tans = i * 2
        tk = K - ruisekiC[i]
        if tk < 0:
            continue

        # A だけ、Bだけで何冊読めるか考える
        idx_a = bisect.bisect_left(ruisekiA[:N+1], tk + ruisekiA[i])
        if idx_a == len(ruisekiA) or ruisekiA[idx_a] != tk + ruisekiA[i]:
            idx_a -= 1
        idx_b = bisect.bisect_left(ruisekiB[:M+1], tk + ruisekiB[i])
        if idx_b == len(ruisekiB) or ruisekiB[idx_b] != tk + ruisekiB[i]:
            idx_b -= 1
        ans = max(ans, max(tans+idx_a-i, tans+idx_b-i))
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
import bisect


def main():
    N, M, K = map(int, input().split())
    A = [int(v) for v in input().split()]
    B = [int(v) for v in input().split()]
    ruisekiA = [0 for _ in range(N+1)]
    ruisekiB = [0 for _ in range(M+1)]
    for i in range(N):
        ruisekiA[i + 1] = ruisekiA[i] + A[i]
    for i in range(M):
        ruisekiB[i + 1] = ruisekiB[i] + B[i]

    ans = 0
    # A を i 個 使う
    for i in range(N+1):
        tans = i
        tk = K - ruisekiA[i]
        if tk < 0:
            break
        idx = bisect.bisect_left(ruisekiB, tk)
        if M+1 == idx or ruisekiB[idx] != tk:
            idx -= 1
        tans += idx
        ans = max(ans, tans)
    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import bisect

def main():
    N, M, K = map(int, input().split())
    A = [int(v) for v in input().split()]
    B = [int(v) for v in input().split()]
    if N < M:
        for _ in range(M-N):
            A.append(0)
    else:
        for _ in range(N-M):
            B.append(0)
    C = [v1+v2 for v1, v2 in zip(A, B)]
    ruisekiA = [0 for _ in range(len(C)+1)]
    ruisekiB = [0 for _ in range(len(C)+1)]
    ruisekiC = [0 for _ in range(len(C)+1)]
    for i in range(len(C)):
        ruisekiA[i + 1] = ruisekiA[i] + A[i]
        ruisekiB[i + 1] = ruisekiB[i] + B[i]
        ruisekiC[i + 1] = ruisekiC[i] + C[i]

    ans = 0
    # i番目までは両方読む
    for i in range(len(C)+1):
        tans = i * 2
        tk = K - ruisekiC[i]
        if tk < 0:
            continue

        # A だけ、Bだけで何冊読めるか考える
        idx_a = bisect.bisect_left(ruisekiA, tk + ruisekiA[i])
        if ruisekiA[idx_a] != tk + ruisekiA[i]:
            idx_a -= 1
        idx_b = bisect.bisect_left(ruisekiB, tk + ruisekiB[i])
        if ruisekiB[idx_b] != tk + ruisekiB[i]:
            idx_b -= 1
        ans = max(ans, max(tans+idx_a-i, tans+idx_b-i))
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
import bisect


def main():
    N, M, K = map(int, input().split())
    A = [int(v) for v in input().split()]
    B = [int(v) for v in input().split()]
    ruisekiA = [0 for _ in range(N+1)]
    ruisekiB = [0 for _ in range(M+1)]
    for i in range(N):
        ruisekiA[i + 1] = ruisekiA[i] + A[i]
    for i in range(M):
        ruisekiB[i + 1] = ruisekiB[i] + B[i]

    ans = 0
    # A を i 個 使う
    for i in range(N+1):
        tans = i
        tk = K - ruisekiA[i]
        if tk < 0:
            break
        idx = bisect.bisect_left(ruisekiB, tk)
        if M+1 == idx or ruisekiB[idx] != tk:
            idx -= 1
        tans += idx
        ans = max(ans, tans)
    print(ans)


if __name__ == '__main__':
    main()