Buggy python submission (verdict: Time Limit Exceeded):
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())
from bisect import bisect


def resolve():
    it = map(int, sys.stdin.read().split())
    N, M, K = next(it), next(it), next(it)

    A = [0] * (N+1)
    B = [0] * (M+1)
    ans = 0
    for i in range(1, N+1):
        A[i] = A[i-1] + next(it)
    for i in range(1, M+1):
        B[i] = B[i-1] + next(it)

    NM = N + M
    for i in range(1, NM+1):
        for j in range(max(0, i-M), min(i, N)+1):
            if A[j] + B[i-j] <= K:
                ans = i
                break
        else:
            break

    print(ans)


if __name__ == "__main__":
    resolve()


Fixed submission:
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    it = map(int, sys.stdin.read().split())
    N, M, K = next(it), next(it), next(it)

    A = [0] * (N+1)
    B = [0] * (M+1)
    ans = 0
    for i in range(1, N+1):
        A[i] = A[i-1] + next(it)
    for i in range(1, M+1):
        B[i] = B[i-1] + next(it)

    lo = 0
    hi = 2*(N+M)+1
    while lo < hi:
        mid = (lo+hi)//2
        for j in range(max(0, mid-M), min(mid, N)+1):
            if A[j] + B[mid-j] <= K:
                lo = mid+1
                break
        else:
            hi = mid

    print(lo-1)


if __name__ == "__main__":
    resolve()

Buggy python submission (verdict: Runtime Error):
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())
from bisect import bisect


def resolve():
    it = map(int, sys.stdin.read().split())
    N, M, K = next(it), next(it), next(it)

    A = [0] * (N+1)
    B = [0] * (M+1)
    ans = 0
    for i in range(1, N+1):
        A[i] = A[i-1] + next(it)
    for i in range(1, M+1):
        B[i] = B[i-1] + next(it)

    NM = N + M
    for i in range(1, N+1):
        for j in range(i+1):
            if A[j] + B[i-j] <= K:
                ans = i
                break
        else:
            break
    k = K - A[N]
    if k > 0:
        i = bisect(B, K-A[N])
        ans = max(ans, i + N -1)

    print(ans)


if __name__ == "__main__":
    resolve()


Fixed submission:
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    it = map(int, sys.stdin.read().split())
    N, M, K = next(it), next(it), next(it)

    A = [0] * (N+1)
    B = [0] * (M+1)
    ans = 0
    for i in range(1, N+1):
        A[i] = A[i-1] + next(it)
    for i in range(1, M+1):
        B[i] = B[i-1] + next(it)

    lo = 0
    hi = 2*(N+M)+1
    while lo < hi:
        mid = (lo+hi)//2
        for j in range(max(0, mid-M), min(mid, N)+1):
            if A[j] + B[mid-j] <= K:
                lo = mid+1
                break
        else:
            hi = mid

    print(lo-1)


if __name__ == "__main__":
    resolve()

Buggy python submission (verdict: Time Limit Exceeded):
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())
from heapq import heappush, heappop

def resolve():
    it = map(int, sys.stdin.read().split())
    N, M, K = next(it), next(it), next(it)
    A = [next(it) for i in range(N)]
    B = [next(it) for i in range(M)]

    dq = []
    heappush(dq, (0, 0, 0, 0))
    ans = 0
    seen = set()
    while dq:
        k, n, i, j = heappop(dq)

        if (i, j) in seen:
            continue
        if k > K:
            break
        seen.add((i, j))
        ans = max(ans, n)

        if i < N:
            heappush(dq, (k+A[i], n+1, i+1, j))
        if j < M:
            heappush(dq, (k+B[j], n+1, i, j+1))

    print(ans)


if __name__ == "__main__":
    resolve()


Fixed submission:
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    it = map(int, sys.stdin.read().split())
    N, M, K = next(it), next(it), next(it)

    A = [0] * (N+1)
    B = [0] * (M+1)
    ans = 0
    for i in range(1, N+1):
        A[i] = A[i-1] + next(it)
    for i in range(1, M+1):
        B[i] = B[i-1] + next(it)

    lo = 0
    hi = 2*(N+M)+1
    while lo < hi:
        mid = (lo+hi)//2
        for j in range(max(0, mid-M), min(mid, N)+1):
            if A[j] + B[mid-j] <= K:
                lo = mid+1
                break
        else:
            hi = mid

    print(lo-1)


if __name__ == "__main__":
    resolve()

Buggy python submission (verdict: Time Limit Exceeded):
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())
from heapq import heappush, heappop

def resolve():
    it = map(int, sys.stdin.read().split())
    N, M, K = next(it), next(it), next(it)
    A = [next(it) for i in range(N)]
    B = [next(it) for i in range(M)]

    dq = []
    heappush(dq, (0, 0, 0, 0))
    ans = 0
    while dq:
        k, n, i, j = heappop(dq)

        if k > K:
            break
        ans = max(ans, n)

        if i < N:
            heappush(dq, (k+A[i], n+1, i+1, j))
        if j < M:
            heappush(dq, (k+B[j], n+1, i, j+1))

    print(ans)


if __name__ == "__main__":
    resolve()


Fixed submission:
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    it = map(int, sys.stdin.read().split())
    N, M, K = next(it), next(it), next(it)

    A = [0] * (N+1)
    B = [0] * (M+1)
    ans = 0
    for i in range(1, N+1):
        A[i] = A[i-1] + next(it)
    for i in range(1, M+1):
        B[i] = B[i-1] + next(it)

    lo = 0
    hi = 2*(N+M)+1
    while lo < hi:
        mid = (lo+hi)//2
        for j in range(max(0, mid-M), min(mid, N)+1):
            if A[j] + B[mid-j] <= K:
                lo = mid+1
                break
        else:
            hi = mid

    print(lo-1)


if __name__ == "__main__":
    resolve()