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()))
 
ans = 0

sums_B = ["" for _ in range(len(B)+1)]

for b in range(len(B)+1):
    sums_B[b] = sum(B[:b])
    
for a in range(len(A)+1):
  sums_A = sum(A[:a])
  if K - sums_A >= 0:
    b_max = max([k for k, v in enumerate(sums_B) if v <= K-sums_A])
    if ans < a+b_max:
        ans = a+b_max
  else:
    break
print(ans)

Fixed submission:
import sys
import math
import itertools
import collections
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()

NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()

def main():
    N, M, K = NMI()
    A = NLI()
    B = NLI()
    
    cumsum_A = [0 for _ in range(len(A)+1)]
    cumsum_B = [0 for _ in range(len(B)+1)]    
    
    cnt = 0
    
    for n in range(N):
        cnt += A[n]
        cumsum_A[n+1] = cnt
        
    cnt = 0
    
    for m in range(M):
        cnt += B[m]
        cumsum_B[m+1] = cnt
    

    
    ans = 0
    b= M
    
    for n in range(N+1):
        remain_K = K - cumsum_A[n]
        if remain_K < 0:
            break
        else:
            for m in range(b,-1,-1):
                if cumsum_B[m]> remain_K:
                    continue
                else:
                    b = m
                    ans = max(ans,n+m)
                break
    
    print(ans)
            
    


if __name__ == '__main__':
    main()

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()))

ans = 0

sums_A = ["" for _ in range(len(A)+1)]
sums_B = ["" for _ in range(len(B)+1)]


for a in range(len(A)+1):
    sums_A[a] = sum(A[:a])

for b in range(len(B)+1):
    sums_B[b] = sum(B[:b])

for a_max in range(max([k for k, v in enumerate(sums_A) if v <= K])+1):
    b_max = max([k for k, v in enumerate(sums_B) if v <= K-sums_A[a_max]])
    if ans < a_max+b_max:
        ans = a_max+b_max
print(ans)


Fixed submission:
import sys
import math
import itertools
import collections
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()

NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()

def main():
    N, M, K = NMI()
    A = NLI()
    B = NLI()
    
    cumsum_A = [0 for _ in range(len(A)+1)]
    cumsum_B = [0 for _ in range(len(B)+1)]    
    
    cnt = 0
    
    for n in range(N):
        cnt += A[n]
        cumsum_A[n+1] = cnt
        
    cnt = 0
    
    for m in range(M):
        cnt += B[m]
        cumsum_B[m+1] = cnt
    

    
    ans = 0
    b= M
    
    for n in range(N+1):
        remain_K = K - cumsum_A[n]
        if remain_K < 0:
            break
        else:
            for m in range(b,-1,-1):
                if cumsum_B[m]> remain_K:
                    continue
                else:
                    b = m
                    ans = max(ans,n+m)
                break
    
    print(ans)
            
    


if __name__ == '__main__':
    main()

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()))

ans = 0

sums_A = ["" for _ in range(len(A)+1)]
sums_B = ["" for _ in range(len(B)+1)]


for a in range(len(A)+1):
    sums_A[a] = sum(A[:a])

for b in range(len(B)+1):
    sums_B[b] = sum(B[:b])


for a in range(len(A)+1):
    K_remain = K - sums_A[a]
    if K_remain >= 0:
        for b in range(len(B)+1):
            if K_remain >= sums_B[b]:
                if ans < a+b:
                    ans = a+b
            else:
                break
    else:
        break
print(ans)

Fixed submission:
import sys
import math
import itertools
import collections
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()

NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()

def main():
    N, M, K = NMI()
    A = NLI()
    B = NLI()
    
    cumsum_A = [0 for _ in range(len(A)+1)]
    cumsum_B = [0 for _ in range(len(B)+1)]    
    
    cnt = 0
    
    for n in range(N):
        cnt += A[n]
        cumsum_A[n+1] = cnt
        
    cnt = 0
    
    for m in range(M):
        cnt += B[m]
        cumsum_B[m+1] = cnt
    

    
    ans = 0
    b= M
    
    for n in range(N+1):
        remain_K = K - cumsum_A[n]
        if remain_K < 0:
            break
        else:
            for m in range(b,-1,-1):
                if cumsum_B[m]> remain_K:
                    continue
                else:
                    b = m
                    ans = max(ans,n+m)
                break
    
    print(ans)
            
    


if __name__ == '__main__':
    main()