Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

def find_nearest(array, value):
    array = np.asarray(array)
    idx = (np.abs(array - value)).argmin()
    return array[idx]

A_len, B_len, K = map(int, input().split(' '))
#print("Aは{0}冊. Bは{1}冊. 上限{2}分".format(A_len, B_len, K))

A = list(map(int, input().split(' ')))
B = list(map(int, input().split(' ')))
#print(A, B)

# A,Bの累積和の配列を出して、A_acc,B_accの要素番地が最大となるような組み合わせを出す

A_acc = []
for idx_A in range(A_len): 
  if(idx_A == 0):
    A_acc.append(A[0])
  else:
    A_acc.append(A_acc[idx_A - 1] + A[idx_A])
A_acc.insert(0, 0)
    
B_acc = []
for idx_B in range(B_len):
  if(idx_B == 0):
    B_acc.append(B[0])
  else:
    B_acc.append(B_acc[idx_B - 1] + B[idx_B])
B_acc.insert(0, 0)

#print(A_acc, B_acc)

max_num = 0
left_time = K
for a_num in range(A_len + 1):
  b_num = 0
  left_time = K - A_acc[a_num]
  #print("Aから{0}冊読んだ場合はそもそも残り{1}分".format(a_num, left_time))
  if(left_time < 0):
    break
  
  #while(True):
  #  print("Bから{0}冊読んでる場合,残り時間{1}".format(b_num, left_time - B_acc[b_num]))
    
  #  if(b_num + 1 > B_len):
  #    break
    
  #  if(left_time - B_acc[b_num + 1] < 0):
  #    break
    
  #  b_num += 1
  nearest_b = find_nearest(B_acc, left_time)
  b_num = B_acc.index(nearest_b)
  if(left_time < nearest_b and b_num > 0):
    b_num -= 1
  #print("最も近い分数は{0}. 冊数は{1}".format(nearest_b, b_num))
    
  #print("結果,A棚から{0}冊、B棚から{1}冊で合計{2}冊で経過時間{3}"
  #      .format(a_num, b_num, a_num + b_num, A_acc[a_num] + B_acc[b_num]))
  max_num = max(max_num, (a_num + b_num))
  #print("現在max{0}".format(max_num))
  
print(max_num)
    


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 i in range(M):
  b.append(b[i] + B[i])

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

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
A_len, B_len, K = map(int, input().split(' '))
#print("Aは{0}冊. Bは{1}冊. 上限{2}分".format(A_len, B_len, K))

A = list(map(int, input().split(' ')))
B = list(map(int, input().split(' ')))
#print(A, B)

# A,Bの累積和の配列を出して、A_acc,B_accの要素番地が最大となるような組み合わせを出す

A_acc = []
for idx_A in range(A_len): 
  if(idx_A == 0):
    A_acc.append(A[0])
  else:
    A_acc.append(A_acc[idx_A - 1] + A[idx_A])
A_acc.insert(0, 0)
    
B_acc = []
for idx_B in range(B_len):
  if(idx_B == 0):
    B_acc.append(B[0])
  else:
    B_acc.append(B_acc[idx_B - 1] + B[idx_B])
B_acc.insert(0, 0)

#print(A_acc, B_acc)

max_num = 0
left_time = K
for a_num in range(A_len + 1):
  b_num = 0
  left_time = K - A_acc[a_num]
  #print("Aから{0}冊読んだ場合はそもそも残り{1}分".format(a_num, left_time))
  if(left_time < 0):
    break
  
  while(True):
    #print("Bから{0}冊読んでる場合,残り時間{1}".format(b_num, left_time - B_acc[b_num]))
    
    if(b_num + 1 > B_len):
      break
    
    if(left_time - B_acc[b_num + 1] < 0):
      break
    
    b_num += 1
    
  #print("結果,A棚から{0}冊、B棚から{1}冊で合計{2}冊で経過時間{3}"
        #.format(a_num, b_num, a_num + b_num, A_acc[a_num] + B_acc[b_num]))
  max_num = max(max_num, (a_num + b_num))
  #print("現在max{0}".format(max_num))
  
print(max_num)
    


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 i in range(M):
  b.append(b[i] + B[i])

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

print(ans)