Buggy python submission (verdict: Time Limit Exceeded):
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

def main():
    import bisect
    def partition(A, p, r):
        x = A[r]
        i = p - 1
        for j in range(p, r):
            if A[j] <= x:
                i += 1
                a = A[i]
                b = A[j]
                A[i] = b
                A[j] = a
        c = A[i + 1]
        A[i + 1] = x
        A[r] = c
        return i + 1
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    time = 0
    cnt = 0
    C = []
    SA = [0]
    SB = [0]
    for a in A:
        SA.append(SA[-1] + a)
    for b in B:
        SB.append(SB[-1] + b)
    for x in range(N + 1):
        L = K - SA[x]
        if L < 0:
            break
        SB.append(L)
        y_max = partition(SB, 0, len(SB) - 1) - 1
        SB.remove(L)
        C.append(y_max + x)
    print(max(C))


if __name__ == "__main__":
    main()

Fixed submission:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for j in range(M):
    b.append(b[j] + B[j])
j = M
ans = []
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans.append(i + j)
ans_max = max(ans)
print(ans_max)

Buggy python submission (verdict: Time Limit Exceeded):
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
time = 0
cnt = 0
C = []
SA =[0]
SB =[0]
for a in A:
    SA.append(SA[-1] + a)
for b in B:
    SB.append(SB[-1] + b)
for x in range(N+1):
    L = K - SA[x]
    if L < 0:
        break
    y_max = 0
    for y in range(M+1):
        T = SB[y]
        if L >= T:
            y_max += 1
        else:
            break
    C.append(y_max - 1 + x)
print(max(C))

Fixed submission:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for j in range(M):
    b.append(b[j] + B[j])
j = M
ans = []
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans.append(i + j)
ans_max = max(ans)
print(ans_max)

Buggy python submission (verdict: Time Limit Exceeded):
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
time = 0
cnt = 0
C = []
for x in range(N+1):
    L = K - sum(A[0:x])
    if L < 0:
        break
    y_max = 0
    for y in range(M+1):
        T = sum(B[0:y])
        if L >= T:
            y_max += 1
        else:
            break
    C.append(y_max - 1 + x)
print(max(C))

Fixed submission:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for j in range(M):
    b.append(b[j] + B[j])
j = M
ans = []
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans.append(i + j)
ans_max = max(ans)
print(ans_max)