Problem:
 Score : 300 points    Problem Statement We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.  It takes us A_i minutes to read the i -th book from the top on Desk A (1 \leq i \leq N) , and B_i minutes to read the i -th book from the top on Desk B (1 \leq i \leq M) .  Consider the following action:   Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.   How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.      Constraints  1 \leq N, M \leq 200000  1 \leq K \leq 10^9  1 \leq A_i, B_i \leq 10^9  All values in input are integers.         Input Input is given from Standard Input in the following format:  N  M  K  A_1  A_2  \ldots  A_N  B_1  B_2  \ldots  B_M       Output Print an integer representing the maximum number of books that can be read.        Sample Input 1 3 4 240
60 90 120
80 150 80 150      Sample Output 1 3  In this case, it takes us 60 , 90 , 120 minutes to read the 1 -st, 2 -nd, 3 -rd books from the top on Desk A, and 80 , 150 , 80 , 150 minutes to read the 1 -st, 2 -nd, 3 -rd, 4 -th books from the top on Desk B, respectively.  We can read three books in 230 minutes, as shown below, and this is the maximum number of books we can read within 240 minutes.   Read the topmost book on Desk A in 60 minutes, and remove that book from the desk.  Read the topmost book on Desk B in 80 minutes, and remove that book from the desk.  Read the topmost book on Desk A in 90 minutes, and remove that book from the desk.        Sample Input 2 3 4 730
60 90 120
80 150 80 150      Sample Output 2 7       Sample Input 3 5 4 1
1000000000 1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000      Sample Output 3 0  Watch out for integer overflows.

Solution (Python):
N, M, K = map(int, input().split(' '))
A_ls = [0] + list(map(int, input().split(' ')))
for i in range(N):
    A_ls[i + 1] += A_ls[i]
B_ls = [0] + list(map(int, input().split(' ')))
for i in range(M):
    B_ls[i + 1] += B_ls[i]

a_cnt, b_cnt, rst = 0, M, 0
for a_cnt in range(N + 1):
    if A_ls[a_cnt] > K:
        break
    while A_ls[a_cnt] + B_ls[b_cnt] > K:
        b_cnt -=1
    rst = max(rst, a_cnt + b_cnt)
print(rst)

Solution (Python):
N, M, K = map(int, input().split())
a_books = list(map(int, input().split()))
b_books = list(map(int, input().split()))
a_time = 0
b_time = 0
a_times = [0 for _ in range(N+1)]
b_times = [0 for _ in range(M+1)]
for i, a in enumerate(a_books):
  a_time += a
  a_times[i+1] = a_time
  
for i, b in enumerate(b_books):
  b_time += b
  b_times[i+1] = b_time
  
result = 0
l = 0
for i in range(N+1):
  if l == M:
    break
  while(l <= M):
    if a_times[N-i] + b_times[l] <= K:
      result = max(result, N-i+l)
      l += 1
    else:
      break
print(result)

Solution (Python):
number=list(map(int,input().split()))
N,M,K=number[0],number[1],number[2]
A=list(map(int,input().split()))
B=list(map(int,input().split()))
a=[0]
b=[0]
for i in range(1,len(A)+1):
    tmp=a[i-1]+A[i-1]
    a.append(tmp)
    
for i in range(1,len(B)+1):
    tmp=b[i-1]+B[i-1]
    b.append(tmp)

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

Solution (Python):
import bisect
from itertools import accumulate

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = [0] + list(accumulate(A))
b = list(accumulate(B))
ans = 0
for i in range(N + 1):
    if (t := K - a[i]) >= 0:
        e = bisect.bisect_right(b, t)
        ans = max(ans, i + e)
print(ans)

Solution (Python):
N,M,K = map(int,input().split())

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

a_sum = [0 for i in range(N+1)]
for i in range(N):
    a_sum[i+1] = a_sum[i] + A[i]

b_sum = [0 for i in range(M+1)]
for i in range(M):
    b_sum[i+1] = b_sum[i] + B[i]

ans = 0

for i in range(N+1):
    t = a_sum[i]
    l = 0
    r = len(b_sum)
    while(l+1<r):
        c = (l+r)//2
        if t+b_sum[c]<=K:
            l = c
        else:
            r = c
    if a_sum[i]+b_sum[l]<=K:
        ans = max(ans,i+l)

print(ans)

Solution (Python):



import numpy as np




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








A = np.array(A)
B = np.array(B)

cum_A = np.cumsum(A)
cum_A = np.insert(cum_A, 0, 0)
cum_B = np.cumsum(B)
cum_B = np.insert(cum_B, 0, 0)

j = M
max_num = 0
for i in range(N + 1):
    while(True):
        
        if j < 0:
            break
        minute = cum_A[i] + cum_B[j]
        if minute <= K:
            if i + j > max_num:
                max_num = i + j
            break
        j -= 1

print(max_num)

Solution (Python):
from bisect import *
from itertools import *
N,M,K = map(int,input().split())
A = [0]+list(accumulate(map(int,input().split())))
B = [0]+list(accumulate(map(int,input().split())))
ans = [0]

for n in range(1+N):
  C = bisect_right(B,K-A[n])-1
  if C!=-1:
    ans+=[C+n]

print(max(ans))

Solution (Python):
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

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

Solution (Python):
from itertools import accumulate

n, m, k=map(int,input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))

j = m
ans = 0

a_acum = [0] + list(accumulate(a_list))
b_acum = [0] + list(accumulate(b_list))

for i in range(n+1):
    if a_acum[i] > k:
        break
    while b_acum[j] > k - a_acum[i] and j > 0:
        j -= 1
    ans = max(ans, i+j)
print(ans)

Solution (Python):
import numpy as np
n,m,k = list(map(int, input().split()))
a_list = np.array(input().split()).astype(int)
b_list = np.array(input().split()).astype(int)
a_sum =[0]
b_sum=[0]
for i in range(n):
    a_sum.append(a_sum[-1]+ a_list[i])
for i in range(m):
    b_sum.append(b_sum[-1] + b_list[i])

total = 0
num = m

for i in range(n+1):
    
    if a_sum[i] > k:
        break
    while (k - a_sum[i]) < b_sum[num]:
        num -=1
        
        if num == -1:
            break
    total = max(i+num, total)
    
    
print(total)

Solution (Python):
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
 
a = [0]
b = [0]
for i in range(n):
  a.append(a[i]+A[i])
for j in range(m):
  b.append(b[j]+B[j])

 
ans = 0
j = m
for i in range(n+1):
  if a[i] > k:
    break
  while (k - a[i]) < b[j]:
    j -= 1
    if j == -1:
      break
  
  ans = max(ans, i+j)
     
print(ans)

Solution (Python):
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 a[i] + b[j] > k:
    j -= 1
  ans = max(ans, i+j)

print(ans)

Solution (Python):
n, m, k = map(int, input().split())
A = [0] + list(map(int,input().split()))
B = [0] + list(map(int,input().split()))
 
for i in range(2,n+1):
    A[i] += A[i-1]
for i in range(2,m+1):
    B[i] += B[i-1]

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

Solution (Python):
n, m, k = map(int, input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

for i in range(1,n):
    A[i] += A[i-1]
for i in range(1,m):
    B[i] += B[i-1]
A.insert(0,0)
B.insert(0,0)

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

Solution (Python):
from itertools import accumulate

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

sa = [0] + list(accumulate(a))
sb = [0] + list(accumulate(b))

ans = 0
p = m
for i in range(n + 1):
    for j in range(p, -1, -1):
        if sa[i] + sb[j] <= k:
            ans = max(ans, i + j)
            p = j
            break
print(ans)

Solution (Python):


import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N, M, K = map(int, input().split())

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

a = [0]
b = [0]
for i in range(N):
    a.append(a[i] + A[i])

for i in range(M):
    b.append(b[i] + B[i])


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

print(count)

Solution (Python):
N, M, K = map(int, input().split(' '))
A_ls = [0] + list(map(int, input().split(' ')))
B_ls = [0] + list(map(int, input().split(' ')))

for i in range(1, N+1):
    A_ls[i] += A_ls[i - 1]

for i in range(1, M+1):
    B_ls[i] += B_ls[i - 1]

a_cnt, b_cnt, rst = 0, M, 0
while a_cnt < N + 1:
    if A_ls[a_cnt] > K:
        break
    while A_ls[a_cnt] + B_ls[b_cnt] > K and b_cnt > 0:
        b_cnt -= 1
    rst = max(rst, a_cnt + b_cnt)
    a_cnt += 1
print(rst)

Solution (Python):
N, M, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))
ans, Bi, Asum, Bsum = 0, M, 0, sum(B)
for Ai in range(N + 1):
    Asum += A[Ai]
    while Asum + Bsum > K and Bi > 0:
        Bsum -= B[Bi]
        Bi -= 1
    if Asum + Bsum <= K:
        ans = max(ans, Ai + Bi)
print(ans)

Solution (Python):
import math
import collections
import fractions
import itertools
import functools
import operator
import bisect

def solve():
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    ruia, ruib = [0], [0]
    for i in range(n): ruia.append(a[i]+ruia[i])
    for i in range(m): ruib.append(b[i]+ruib[i])
    ans = 0
    j = m
    for i in range(n+1):
        if ruia[i] > k:
            break
        while(ruib[j]>k-ruia[i]):
            j -= 1
        ans = max(ans, i+j)
    print(ans)
    return 0

if __name__ == "__main__":
    solve()

Solution (Python):
N,M,K=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a_s=[0]
b_s=[0]
for i in range(N):
  if a_s[i]+a[i]>K:
    break
  a_s.append(a[i]+a_s[i])
for i in range(M):
  if b_s[i]+b[i]>K:
    break
  b_s.append(b[i]+b_s[i])
bn=len(b_s)-1
ans=0
for i in range(len(a_s)):
  while a_s[i]+b_s[bn]>K:
    bn-=1
  ans=max(ans,i+bn)
  
print(ans)

Solution (Python):
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = [0]
y = [0]
for i in range(n):
    x.append(a[i] + x[i])
for j in range(m):
    y.append(b[j] + y[j])
ans = 0
q = m
for p in range(n + 1):
    if x[p] > k:
        break
    while y[q] > k - x[p]:
        q = q - 1
    ans = max(ans, p + q)
print(ans)

Solution (Python):
N, M, K = map(int, input().split(' '))
A_ls = [0] + list(map(int, input().split(' ')))
B_ls = [0] + list(map(int, input().split(' ')))

for i in range(1, N + 1):
    A_ls[i] += A_ls[i - 1]
for i in range(1, M + 1):
    B_ls[i] += B_ls[i - 1]

b_cnt, rst = M, 0
for a_cnt in range(N + 1):
    if A_ls[a_cnt] > K:
        break
    while A_ls[a_cnt] + B_ls[b_cnt] > K:
        b_cnt -= 1
    rst = max(rst, a_cnt + b_cnt)
print(rst)

Solution (Python):
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)

Solution (Python):



import numpy

def main():
  _, _, k = map(int, input().strip().split())
  la = numpy.cumsum([0] + list(map(int, input().strip().split())))
  lb = numpy.cumsum([0] + list(map(int, input().strip().split())) + [10**9+5])
  
  def bs(x):
    s, t = 0, len(lb) - 1
    while t > s + 1:
      m = (s + t) // 2
      if lb[m] == x:
        return m
      if lb[m] > x:
        t = m
      else:
        s = m
    return s
  
  ans = 0
  for i, a in enumerate(la):
    if k - a >= 0:
      ans = max(ans, i + bs((k - a)))
  print(ans)

if __name__=='__main__':
  main()

Solution (Python):
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

acum1=[0]
for i in range(n):
	acum1.append(acum1[-1]+a[i])
acum2=[0]
for i in range(m):
	acum2.append(acum2[-1]+b[i])
ans = 0
j = m
for i in range(n + 1):
	if acum1[i] > k:
		break
	while (j > 0) and (acum1[i] + acum2[j] > k):
		j -= 1
	ans = max(ans, i + j)
print(ans)

Solution (Python):
n, m, k = map(int, input().split())

a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))

sum = 0
for i in b:
    sum += i

ans = 0
j = m
for i in range(0, n+1):
    sum += a[i]
    while j > 0 and sum > k:
        sum -= b[j]
        j -= 1
    if sum <= k:
        ans = max(ans, i+j)

print(ans)

Solution (Python):
import numpy as np

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


i = 0
A_sum = [0]
while (i < len(A)) and (A_sum[i] + A[i] <= K):
    A_sum.append(A_sum[i] + A[i])
    i += 1
    
i = 0
B_sum = [0]
while (i < len(B)) and (B_sum[i] + B[i] <= K):
    B_sum.append(B_sum[i] + B[i])
    i += 1


max_book = 0
ind = len(B_sum) - 1
for i in range(len(A_sum)):
    while (A_sum[i] + B_sum[ind] > K) and (ind > 0):
        ind -= 1
    if i + ind > max_book:
        max_book = i + ind

print(max_book)

Solution (Python):
from collections import deque
N, M, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
da = deque()
i = 0
tmpK = 0
while tmpK <= K and i < N:
    tmpK += A[i]
    da.append(A[i])
    i += 1

if (tmpK > K):
    i -= 1
    tmpK -= da.pop()


db = deque()
j = 0
while tmpK <= K and j < M:
    tmpK += B[j]
    db.append(B[j])
    j += 1

if (tmpK > K):
    j -= 1
    tmpK -= db.pop()
tmptot = i+j
while len(da) > 0:
    tmpK -= da.pop()
    i -= 1
    while tmpK <= K and j < M:
        tmpK += B[j]
        db.append(B[j])
        j += 1
    
    if (tmpK > K):
        j -= 1
        tmpK -= db.pop()
    if tmptot < i+j:
        tmptot = i+j
print(tmptot)

Solution (Python):
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]


def inverse(a):
    return pow(a, mod - 2, mod)


def main():
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = [0] * (m + 1)
    for i in range(m):
        c[i+1] = c[i] + b[i]

    s = 0
    ans = 0
    for i in range(n+1):
        lft = 0
        rgt = m+1
        while rgt - lft > 1:
            mid = (lft + rgt) // 2
            if s + c[mid] <= k:
                lft = mid
            else:
                rgt = mid
        ans = max(ans, i + lft)
        if i < n:
            s += a[i]
        if s > k:
            break
    print(ans)

main()

Solution (Python):
from bisect import bisect_right
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ruisekiwa_of_a = [0]
ruisekiwa_of_b = [0]
for a in A:
    ruisekiwa_of_a.append(ruisekiwa_of_a[-1]+a)
for b in B:
    ruisekiwa_of_b.append(ruisekiwa_of_b[-1]+b)


ans = 0
for i in range(N+1):
    if ruisekiwa_of_a[i] > K:
        continue
    tmp = i
    tmp += bisect_right(ruisekiwa_of_b, K-ruisekiwa_of_a[i])-1
    ans = max(ans, tmp)
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline

n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))




s = 0
j = 0
for i in range(n):
    if s + a[i] > k:
        break
    else:
        s += a[i]
        j += 1


ans = [j]

for l in range(m):
    flag = True
    s += b[l]
    while s > k:
        s -= a[j-1]
        j -= 1
        if j < 0:
            flag = False
            break
    
    if not flag:
        break
    else:
        ans.append(l + 1 + j)
        

print(max(ans))

Solution (Python):
N, M, K = map(int,input().split())

A = list(map(int,input().split()))
A.insert(0, 0)
B = list(map(int,input().split()))
a = []
b = []

def nibun(L,l,r,target):

  wrk = -(-(l+r)//2)
  

  
  if r == l:
    if r == len(L):
      return 0
    else:
      return wrk + 1
  
  if l == (len(L)-1):
    if L[wrk-1] > target:
      return wrk
    else:
      return 0

  if L[wrk] == target:
    return wrk+1

  elif L[wrk] > target:
    return nibun(L,l,wrk-1,target)

  else:
    return nibun(L,wrk,r,target)

  
s = 0
for i,e in enumerate(B):
  s += e 
  b.append(s)

s = 0
ans = 0
for i in range(len(A)):


  s += A[i]
  if s > K:
    break
  else:  
    wrk = nibun(b,-1,len(b),K-s)
    
    ans=max(ans,i+wrk)


print(ans)

Solution (Python):

import bisect
n, m, k = map(int, input().split())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))

acum = [0]
for i in range(n):
    acum.append(al[i]+acum[i])

bcum = [0]
for i in range(m):
    bcum.append(bl[i]+bcum[i])
ans = 0
for i in range(n+1):
    rsd = k-acum[i]
    if rsd < 0:
        break
    
    
    
    ind = bisect.bisect_right(bcum, rsd)
    ans = max(ans, i+ind-1)
print(ans)

Solution (Python):
n, m, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))

for i in range(1, n + 1):
    a[i] += a[i - 1]
for i in range(1, m + 1):
    b[i] += b[i - 1]

ans = 0
b_cnt = m

for a_cnt in range(n+1):
    if a[a_cnt] > k:
        break
    while a[a_cnt] + b[b_cnt] > k:
        b_cnt -= 1
    ans = max(ans, a_cnt + b_cnt)

print(ans)

Solution (Python):
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
t, ans = sum(B), 0
j = M
for i in range(N+1):
   while j>0 and t>K:
       j -= 1
       t -= B[j]
   if t>K: break
   ans = max(ans, i+j)
   if i==N: break
   t += A[i]

print(ans)

Solution (Python):
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
from itertools import accumulate
accumulated1 = [0] + list(accumulate(A))
accumulated2 = [0] + list(accumulate(B)) + [10**10]
def check(x,now):
    if accumulated1[now] + accumulated2[x] <= K: return True
    else: return False




def bisect(l,r,now):
    if r - l == 1: return  l
    mid = (r+l)//2
    

    

    
    

    
    

    
    
    

    if check(mid,now):
        
        return bisect(mid,r,now)
    else:
        
        return bisect(l,mid,now)


ans = 0
for i in range(N+1):
    if accumulated1[i] > K: pass
    else: ans = max(ans,bisect(0,M+1,i) + i)
print(ans)

Solution (Python):
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
A=[0 for i in range(n)]
B=[0 for i in range(m)]
A[0]=a[0]
B[0]=b[0]
for i in range(n-1):
    A[i+1]=a[i+1]+A[i]

for i in range(m-1):
    B[i+1]=b[i+1]+B[i]

ans=0
A.insert(0,0)
B.insert(0,0)

for i in range(n+1):
    x=0
    y=m
    j=(x+y)//2
    if A[i]+B[m]<=k:
        ans=max(ans,i+m)
    elif not A[i]+B[0]>k:
        
        
        while y-x>1:
            if A[i]+B[j]<=k:
                x=j
            else:
                y=j
            j=(x+y)//2
        ans=max(ans,i+x)
    
print(ans)

Solution (Python):
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
A=[0 for i in range(n)]
B=[0 for i in range(m)]
A[0]=a[0]
B[0]=b[0]
for i in range(n-1):
    A[i+1]=a[i+1]+A[i]

for i in range(m-1):
    B[i+1]=b[i+1]+B[i]

ans=0
A.insert(0,0)
B.insert(0,0)

for i in range(n+1):
    x=0
    y=m
    j=(x+y)//2
    if A[i]+B[m]<=k:
        ans=max(ans,i+m)
    elif not A[i]+B[0]>k:
        
        
        while y-x>1:
            if A[i]+B[j]<=k:
                x=j
            else:
                y=j
            j=(x+y)//2
        ans=max(ans,i+x)
    
print(ans)

Solution (Python):
import bisect
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
A_cum = [0]
B_cum = [0]
A_cum[0] = A[0]
for j in range(len(A)-1):
    A_cum.append(A_cum[j]+ A[j+1])
B_cum[0] = B[0]
for l in range(len(B)-1):
    B_cum.append(B_cum[l] + B[l+1])
for i in range(len(A_cum)):
    k = A_cum[i]
    if k >K:
        break
    b = bisect.bisect(B_cum,K-k)
    check = i+b+1
    if check>ans:
        ans = check
check = bisect.bisect(B_cum,K)
if check>ans:
    ans = check    
print(ans)

Solution (Python):
import bisect
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
A_cum = [0]
B_cum = [0]
A_cum[0] = A[0]
for j in range(len(A)-1):
    A_cum.append(A_cum[j]+ A[j+1])
B_cum[0] = B[0]
for l in range(len(B)-1):
    B_cum.append(B_cum[l] + B[l+1])
for i in range(len(A_cum)):
    k = A_cum[i]
    if k >K:
        break
    b = bisect.bisect(B_cum,K-k)
    check = i+b+1
    if check>ans:
        ans = check
check = bisect.bisect(B_cum,K)
if check>ans:
    ans = check    
print(ans)

Solution (Python):
from bisect import bisect_left, bisect_right
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ruisekiwa_of_A = [0]
ruisekiwa_of_B = [0]
for a in A:
    ruisekiwa_of_A.append(ruisekiwa_of_A[-1]+a)
for b in B:
    ruisekiwa_of_B.append(ruisekiwa_of_B[-1]+b)

ans = 0
for i in range(N+1):
    tmp = 0
    if K >= ruisekiwa_of_A[i]:
        tmp = i
    else:
        continue
    tmp += bisect_right(ruisekiwa_of_B, K-ruisekiwa_of_A[i])-1
    ans = max(ans, tmp)
print(ans)

Solution (Python):
def get_cusum(lst):
    cusum = [0] + lst
    for i in range(1, len(cusum)):
        cusum[i] = cusum[i] + cusum[i-1]
    return cusum


def main():

    n, m, k = map(int, input().split(" "))
    book_a = get_cusum(list(map(int, input().split(" "))))
    book_b = get_cusum(list(map(int, input().split(" "))))
    ans = 0
    top = m

    
    

    for i in range(n + 1):
        if book_a[i] > k:
            break

        while book_b[top] > k - book_a[i]:
            top -= 1

        ans = max(ans, i+top)

    print(ans)


main()

Solution (Python):
n, m, k = map(int, input().split())
a_books = list(map(int,input().split()))
b_books = list(map(int,input().split()))
sum1 = [0]
sum2 = [0]
for i in range(n):
 sum1.append(sum1[-1]+a_books[i])
for i in range(m):
 sum2.append(sum2[-1]+b_books[i])
ans=0
import bisect
for i in range(n+1):
    if sum1[i] > k:
        break
    j = bisect.bisect_right(sum2, k-sum1[i])-1
    ans = max(ans, i+j)
print(ans)

Solution (Python):
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=0
for i in range(n+1):
  if a[i]>k:
    break
  for j in range(m,-1,-1):
    if a[i]+b[j]<=k:
      ans=max(ans,i+j)
      m=j
      break
print(ans)

Solution (Python):




n,m,k=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
from itertools import accumulate
a=[0]+list(accumulate(a))
b=[0]+list(accumulate(b))
from bisect import bisect_right
c=bisect_right(a,k)
ans=0
for i in range(c):
  ans=max(ans,i+bisect_right(b,k-a[i])-1)
  
  
print(ans)

Solution (Python):

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

x = [0] * (N + 1)
y = [0] * (M + 1)
for i in range(N):
    x[i + 1] = x[i] + A[i]

for i in range(M):
    y[i + 1] = y[i] + B[i]

j = M
ans = 0
for i in range(N + 1):
    if x[i] > K:
        continue
    while j >= 0 and x[i] + y[j] > K:
        j -= 1
    ans = max(ans, i + j)
print(ans)

Solution (Python):
N,M,K=map(int,input().split())
A,B=[0],[0]
A+=map(int,input().split())
B+=map(int,input().split())

for i in range(1,N+1):
    A[i]+=A[i-1]
for i in range(1,M+1):
    B[i]+=B[i-1]

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

print(ans)

Solution (Python):
N,M,K=map(int,input().split())
A,B=[0],[0]
A+=map(int,input().split())
B+=map(int,input().split())

for i in range(1,N+1):
    A[i]+=A[i-1]
for i in range(1,M+1):
    B[i]+=B[i-1]

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

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
enum = enumerate
INF = 1001001001

import collections
import random

def linput(ty=int, cvt=list):
	return cvt(map(ty,input().split()))

def gcd(a: int, b: int):
	while b: a, b = b, a%b
	return a

def lcm(a: int, b: int):
	return a * b // gcd(a, b)

def dist(x1,y1,x2,y2):
	return abs(x1-x2)+abs(y1-y2)

def ran():
	vRan = [random.randint(1,5) for i in range(8)]
	return vRan

def main():
	if 1:
		N,M,K = linput()
		vA = linput()
		vB = linput()
	else:
		
		
		
		N,M,K = 0,0,8
		vA = ran()
		vB = ran()
		print(vA,vB,sep="\n")
	
	res = 0
	
	cnt = 0
	t = 0
	for a in vA:
		if t+a<=K:
			t += a
			cnt += 1
		else: break
	
	res = max(res,cnt)
	vJ = vA[0:cnt]
	for b in vB:
		while t+b>K:
			if not vJ: break
			j = vJ.pop()
			t -= j
			cnt -= 1
		if t+b<=K:
			t += b
			cnt += 1
			res = max(res,cnt)
		else:
			break
		
	
	print(res)
	
	
	

if __name__ == "__main__":
	main()

Solution (Python):
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

aa = [0]*(n+1)
for i in range(n):
    aa[i+1] = aa[i] + a[i]

bb = [0]*(m+1)
for i in range(m):
    bb[i+1] = bb[i] + b[i]

j = m
ans = 0
for i in range(n+1):
    if aa[i] > k:
        break
    while bb[j] > k-aa[i]:
        j -= 1
    ans = max(ans, i+j)

print(ans)

Solution (Python):
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

tmp = 0
aa = [0]*(n+1)
for i in range(n):
    tmp += a[i]
    aa[i+1] = tmp

tmp = 0
bb = [0]*(m+1)
for i in range(m):
    tmp += b[i]
    bb[i+1] = tmp

j = m
ans = 0
for i in range(n+1):
    if aa[i] > k:
        break
    while bb[j] > k-aa[i] and j >= 0:
        j -= 1
    ans = max(ans, i+j)

print(ans)

Solution (Python):
def main():
    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 a[i] + b[j] > K:
            j -= 1

        ans = max(ans, i + j)

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
from bisect import bisect_right as br
from itertools import accumulate as ac
n,m,k=map(int,input().split())
a=list(ac([0]+list(map(int,input().split()))))
b=list(ac([0]+list(map(int,input().split()))))
l=0
for i in range(n+1):
    if k<a[i]:
        break
    else:
        l=max(l,i+br(b,k-a[i])-1)
print(l)

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

sum = 0
i = 0
j = 0

while (sum + A[i]) <= K:
  sum += A[i]
  i += 1
  if i >= N:
    break
  
while (sum + B[j]) <= K:
  sum += B[j]
  j += 1
  if j >= M:
    break
  
max = i + j

if max == M+N:
  print(max)
else:
  while (0 < i and j < M):
    sum -= A[i-1] 
    i -= 1
    while (sum + B[j]) <= K:
      sum += B[j]
      j += 1
      if j >= M:
        break
    if (i + j) > max:
      max = (i + j)
  print(max)

Solution (Python):
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)

Solution (Python):

import sys
sys.setrecursionlimit(10**7)
import bisect
import heapq
import itertools
import math
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]







n,m,k = MI()
a = LI()
b = LI()
a_cum = [0]
b_cum = [0]
ans = 0
for i in range(1,n+1):
    a_cum.append(a[i-1]+a_cum[i-1])
for i in range(1,m+1):
    b_cum.append(b[i-1]+b_cum[i-1])
for i in range(m+1):
    K = k-b_cum[i]
    if K >= 0:
    
      j = bisect.bisect_right(a_cum, K) - 1
      ans = max(ans,i+j)
print(ans)

Solution (Python):
from bisect import bisect_right

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

A_sum = [0]
B_sum = [0]
for i in range(N):
    A_sum.append(A_sum[i]+A[i])
for i in range(M):
    B_sum.append(B_sum[i]+B[i])

ans = 0

for i in range(N+1):
    cntA = i 
    rest = K - A_sum[i] 
    if rest < 0:
        break
    cntB = bisect_right(B_sum,rest)-1 
    ans = max(ans,cntA + cntB)
print(ans)

Solution (Python):
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)

Solution (Python):
n,m,p=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

a=[0]*(n+1) ; b=[0]*(m+1)
for i in range(n):
    a[i+1]+=a[i]+A[i]
for j in range(m):
    b[j+1]=b[j]+B[j]
    

now=-1
import bisect as bi
for i in range(n+1):
    if a[i]>p : break
    G=p-a[i]   
    now=max(bi.bisect(b, G)+i-1, now)

print(now)

Solution (Python):
n,m,k=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]

def make_sumlist(book_list):
    sumnum=0
    container=[0]
    for i in book_list:
        container.append(sumnum+i)
        sumnum+=i
    return container

total_a=make_sumlist(a)
total_b=make_sumlist(b)







def readable(r):
    
    if r>n+m:
        return False
    if r==0:
        return True
    max_book=100000000000
    for a_n in range(max(0,r-m),min(n,r)+1):
        b_n=r-a_n
        
        book_sum=total_a[a_n]+total_b[b_n]
        
        max_book=min(max_book,book_sum)
    if max_book<=k:
        return True
    return False

def nibuntansaku(start,end):
    if start==end:
        return start
    middle=(start+end)//2+1
    if readable(middle):
        start=middle
    else:
        end=middle-1
    return nibuntansaku(start,end)

print(nibuntansaku(0,k))