Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left
import numpy as np
def main():
    N, M, K = map(int, input().split())
    A = np.array([0] + list(map(int, input().split())), dtype=np.int64)
    B = np.array([0] + list(map(int, input().split())), dtype=np.int64)

    As = np.cumsum(A)
    Bs = np.cumsum(B)

    count = 0
    Amax = bisect_left(As, K+1)
    Bmax = bisect_left(Bs, K+1)

    for i in range(Amax):
        j = M
        while As[i] + Bs[j] > K:
            j -= 1
        count = max(count, (i+j))

    print(count)

if __name__ == '__main__':
    main()

Fixed submission:
from bisect import bisect_right
import numpy as np
def main():
    N, M, K = map(int, input().split())
    A = np.array([0] + list(map(int, input().split())), dtype=np.int64)
    B = np.array([0] + list(map(int, input().split())), dtype=np.int64)

    As = np.cumsum(A)
    Bs = np.cumsum(B)

    count = 0

    for i, a in enumerate(As):
        if a > K:
            break
        j = bisect_right(Bs, K-a)
        #print(f"i={i} j={j} Bs={Bs} cost={K-a}")
        count = max(count, (i+j-1))

    print(count)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heapify, heappop, heappush
def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    start = (0, (-1,-1))
    hq = [start]
    heapify(hq)
    count = -2
    footprint = set()
    while True:
        if len(hq) == 0:
            break
        cost, (i, j) = heappop(hq)
        if cost > K:
            break
        if (i, j) in footprint:
            continue
        footprint.add((i,j))
        count = max(count, i+j)
        #print(f"cost={cost} i={i} j={j}")

        if i+1 < len(A):
            heappush(hq, (cost + A[i+1], (i+1, j)))
        if j+1 < len(B):
            heappush(hq, (cost + B[j+1], (i, j+1)))

    print(count+2)



if __name__ == '__main__':
    main()

Fixed submission:
from bisect import bisect_right
import numpy as np
def main():
    N, M, K = map(int, input().split())
    A = np.array([0] + list(map(int, input().split())), dtype=np.int64)
    B = np.array([0] + list(map(int, input().split())), dtype=np.int64)

    As = np.cumsum(A)
    Bs = np.cumsum(B)

    count = 0

    for i, a in enumerate(As):
        if a > K:
            break
        j = bisect_right(Bs, K-a)
        #print(f"i={i} j={j} Bs={Bs} cost={K-a}")
        count = max(count, (i+j-1))

    print(count)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import numpy as np
from collections import deque
def main():
    N, M, K = map(int, input().split())
    A = deque(list(map(int, input().split())))
    B = deque(list(map(int, input().split())))
    
    cost = K
    count = 0
    while True:
        if len(A) ==0 and len(B) == 0:
            break
        elif len(A) == 0:
            cost -= B.popleft()
        elif len(B) == 0:
            cost -= A.popleft()

        else:
            a = A[0] + A[1]
            b = B[0]
            if a < b:
                cost -= A.popleft()
            else:
                cost -= B.popleft()

        if cost < 0:
            break
        count += 1
    
    print(count)


if __name__ == '__main__':
    main()


Fixed submission:
from bisect import bisect_right
import numpy as np
def main():
    N, M, K = map(int, input().split())
    A = np.array([0] + list(map(int, input().split())), dtype=np.int64)
    B = np.array([0] + list(map(int, input().split())), dtype=np.int64)

    As = np.cumsum(A)
    Bs = np.cumsum(B)

    count = 0

    for i, a in enumerate(As):
        if a > K:
            break
        j = bisect_right(Bs, K-a)
        #print(f"i={i} j={j} Bs={Bs} cost={K-a}")
        count = max(count, (i+j-1))

    print(count)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import numpy as np
def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    
    ia = 0
    ib = 0
    cost = 0
    while True:
        if ia < len(A) and ib < len(B):
            if A[ia] < B[ia]:
                if cost + A[ia] > K:
                    break
                ia += 1
                cost += A[ia]
            else:
                if cost + B[ib] > K:
                    break
                ib += 1
                cost += B[ib]
        elif ia < len(A):
            if cost + A[ia] > K:
                break
            ia += 1
            cost += A[ia]
        elif ib < len(B):
            if cost + B[ib] > K:
                break
            ib += 1
            cost += B[ib]
        else:
            break
    
    count = ia + ib
    print(count)


if __name__ == '__main__':
    main()


Fixed submission:
from bisect import bisect_right
import numpy as np
def main():
    N, M, K = map(int, input().split())
    A = np.array([0] + list(map(int, input().split())), dtype=np.int64)
    B = np.array([0] + list(map(int, input().split())), dtype=np.int64)

    As = np.cumsum(A)
    Bs = np.cumsum(B)

    count = 0

    for i, a in enumerate(As):
        if a > K:
            break
        j = bisect_right(Bs, K-a)
        #print(f"i={i} j={j} Bs={Bs} cost={K-a}")
        count = max(count, (i+j-1))

    print(count)

if __name__ == '__main__':
    main()