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):
import sys
input = sys.stdin.readline

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

Solution (Python):
import sys
input = sys.stdin.readline
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] + a[i] > K:
        j -= 1
    
    ans = max(ans, i + j)

print(ans)

Solution (Python):





import itertools
import bisect

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



a_cumsum = list(itertools.accumulate(a))
b_cumsum = list(itertools.accumulate(b))



books = []



for i in range(len(a_cumsum)):
    minutes = 0
    numbers = 0

    a_minutes = a_cumsum[i]  
    minutes += a_minutes
    
    if minutes <= k:

        
        numbers += i

        
        rest_minutes = k - a_minutes
        
        
        if b_cumsum[-1] == rest_minutes:
            b_books = len(b_cumsum) - 1
        else:
            
            b_books = bisect.bisect_right(b_cumsum, rest_minutes)
            b_books -= 1
    
        numbers += b_books
    
    books.append(numbers)

print(max(books))

Solution (Python):
import itertools
from bisect import bisect
N, M, K = map(int, input().split())
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
A_sum = [0]
for a in A:
    A_sum.append(A_sum[-1]+a)
B_sum = [0]
for b in B:
    B_sum.append(B_sum[-1]+b)
ans = 0
for i, num in enumerate(A_sum):
    target = K - num
    if target < 0:
        break
    j = bisect(B_sum, target)
    ans = max(ans, i+j-1)
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(' ')))

cum_a = np.r_[[0], np.cumsum(A)]
cum_b = np.r_[[0], np.cumsum(B)]

ans = 0
b_best = m
for a in range(0, n+1):
  ng = False
  for b in range(b_best, -2, -1):
    if b == -1:
      ng = True
      break
    
    if cum_a[a] + cum_b[b] <= k:
      b_best = b
      ans = max(ans, a + b)
      break
  if ng:
    break

print(ans)

Solution (Python):
n,m,k=map(int,input().split())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
acum1=[0]
for i in range(n): 
 acum1.append(acum1[-1]+arr1[i])
acum2=[0]
for i in range(m):
 acum2.append(acum2[-1]+arr2[i])
ans=0
j=m
for i in range(n+1):
 if acum1[i]>k: 
   break
 while acum2[j]>k-acum1[i] and j>0: 
   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()))

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

from sys import stdin

import numpy as np








def _li():
    return list(map(int, stdin.readline().split()))


def _li_():
    return list(map(lambda x: int(x) - 1, stdin.readline().split()))


def _lf():
    return list(map(float, stdin.readline().split()))


def _ls():
    return stdin.readline().split()


def _i():
    return int(stdin.readline())


def _f():
    return float(stdin.readline())


def _s():
    return stdin.readline()[:-1]


N, M, K = _li()
A_list = _li()
B_list = _li()



cum_a = np.cumsum([0] + A_list)
cum_b = np.cumsum(B_list)









ans = 0
for i, a in enumerate(cum_a):
    if a > K:
        cur = 0
    else:
        cur = i
    cand = np.searchsorted(cum_b, K - a, side="right")
    ans = max(cur + cand, ans)

print(ans)

Solution (Python):

from sys import stdin


from itertools import accumulate
from bisect import bisect_right





def _li():
    return list(map(int, stdin.readline().split()))


def _li_():
    return list(map(lambda x: int(x) - 1, stdin.readline().split()))


def _lf():
    return list(map(float, stdin.readline().split()))


def _ls():
    return stdin.readline().split()


def _i():
    return int(stdin.readline())


def _f():
    return float(stdin.readline())


def _s():
    return stdin.readline()[:-1]


def search(cum1, cum2, iter_max, limit):
    ans = 0
    for (i,) in range(iter_max):
        if cum1[i] > limit:
            cur = 0
        else:
            cur = i
        cand = bisect_right(cum2, limit - cum1[i])
        ans = max(cur + cand, ans)
    return ans


N, M, K = _li()
A_list = _li()
B_list = _li()

cum_a = [0] + list(accumulate(A_list))
cum_b = list(accumulate(B_list))

ans = 0
for i, a in enumerate(cum_a):
    if a > K:
        cur = 0
    else:
        cur = i
    cand = bisect_right(cum_b, K - a)
    ans = max(cur + cand, ans)

print(ans)

Solution (Python):


def solve():
    N, M, K = list(map(int, input().split()))
    As = list(map(int, input().split()))
    Bs = list(map(int, input().split()))

    sumAs = [0]*(N+1)
    for i in range(1, N+1):
        sumAs[i] = sumAs[i-1] + As[i-1]

    sumBs = [0]*(M+1)
    for i in range(1, M+1):
        sumBs[i] = sumBs[i-1] + Bs[i-1]

    i = 0
    while True:
        if i==(N+1) or sumAs[i] > K:
            break
        i += 1
    i = max(0, i-1)

    j = 0
    while True:
        if j==(M+1) or sumBs[j] + sumAs[i] > K:
            break
        j += 1
    j = max(0, j-1)

    ans = i+j

    
    for n in range(i, -1, -1):
        while True:
            if j==(M+1) or sumBs[j] + sumAs[n] > K:
                break
            j += 1
        j = max(0, j-1)
        ans = max(ans, n+j)

    print(ans)


if __name__ == "__main__":
    solve()

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(N):
    A[i+1]+=A[i]
for i in range(M):
    B[i+1]+=B[i]

idx=N
ans=0
for i in range(N):
    if A[i]>K:
        idx=i-1
        break

idx2=0
for i in range(idx,-1,-1):
    while idx2<M and A[i]+B[idx2+1]<=K:
        idx2+=1
    ans=max(ans,i+idx2)

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,k = map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

asum=[0]
bsum=[0]
for i in range(n):
    asum.append(asum[i]+a[i])
for i in range(m):
    bsum.append(bsum[i]+b[i])

t=0
for i in range(n+1):
    if asum[i]>k:
        break
    now=k-asum[i]
    while bsum[m]>now:
        m-=1
    if t<i+m:
        t=i+m
        
print(t)

Solution (Python):
nums=[int(e) for e in input().split()]
A=[int(e) for e in input().split()]
B=[int(e) for e in input().split()]

a, b = [0], [0]
for i in range(nums[0]):
    a.append(a[i]+A[i])
for i in range(nums[1]):
    b.append(b[i]+B[i])

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

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

Ac = [0]*(N+1)
Bc = [0]*(M+1)
for i in range(1, N+1):
    Ac[i] = Ac[i-1] + A[i-1]
for j in range(1, M+1):
    Bc[j] = Bc[j-1] + B[j-1]

ans = 0
for i in range(N+1):
    n = K - Ac[i]
    if n < 0: break
    tmp = bisect.bisect_right(Bc, n) - 1
    ans = max(ans, i + tmp)
    
print(ans)

Solution (Python):


n, m, k = map(int, input().split())
arr1 = list(map(int,input().split()))
arr2 = list(map(int,input().split()))

acum1 = [0]
for i in range(n):
    acum1.append(acum1[-1]+arr1[i])

acum2 = [0]
for i in range(m):
    acum2.append(acum2[-1]+arr2[i])

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

Solution (Python):






n, m, k = map(int, input().split())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))

acum1 = [0]
for i in range(n):
    acum1.append( acum1[-1] + arr1[i] )

acum2 = [0]
for i in range(m):
    acum2.append( acum2[-1] + arr2[i])

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

            j -= 1
    ans = max(ans,i+j)

print(ans)

Solution (Python):


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

answer = 0

currA = sum(A)
currB = 0
b_index = 0

for a_index in range(N, -1, -1):
    currA -= A[a_index]
    currK = K - currA
    if currK < 0: continue
    
    while currB <= currK and b_index <= (M - 1):
        nextB = currB + B[b_index]
        if nextB > currK: break
        
        currB = nextB
        b_index += 1
    
    answer = max(answer, a_index + b_index)
    
print(answer)

Solution (Python):
anum,bnum,acc = map(int,input().split())
alist = list(map(int,input().split()))
blist = list(map(int,input().split()))

asum = [0]
bsum = [0]
ans = 0
for i in range(anum):
    asum.append(asum[i]+alist[i])
for i in range(bnum):
    bsum.append(bsum[i]+blist[i])

b = bnum
for a in range(anum+1):
    if asum[a] > acc:
        break
    while asum[a] + bsum[b] > acc:
        b -=1
    ans = max(ans,a+b)

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

Solution (Python):
n ,m ,k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
 
sa = [0]
sb = [0]
 
 
for i in range(n):
    sa.append(sa[i]+a[i])
 
for i in range(m):
    sb.append(sb[i]+b[i])
 
ans = 0
 
for i in range(n+1):
    if sa[i] > k:
        break
    mb = 0
    lb = m+1
    for j in range(100):
        mid = (mb+lb)//2
        if sb[mid] + sa[i] <= k:
            mb = mid
        else:
            lb = mid
    ans = max(ans, i + mb)
 
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):
from bisect import bisect
import itertools
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

sum_a = list(itertools.accumulate(a))
sum_b = list(itertools.accumulate(b))

nokori = k
counter = 0
ans = [0]

sum_a = [0] + sum_a 

for i in sum_a:
    if i > k:
        break
    ans.append(counter + bisect(sum_b, k - i))
    counter +=1
print(max(ans))

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

N = int(N)
M = int(M)
K = int(K)

A = list(input().split())
A = [int(c) for c in A]

Sum_A = [0]
ele_A = 0
a = 0

while Sum_A[-1] + A[a] <= K:
    ele_A += A[a]
    a += 1
    Sum_A.append(ele_A)
    if a == len(A):
        break

B = list(input().split())
B = [int(c) for c in B]

Sum_B = [0]
ele_B = 0
b = 0

while Sum_B[-1] + B[b] <= K:
    ele_B += B[b]
    b += 1
    Sum_B.append(ele_B)
    if b == len(B):
        break

h = len(Sum_A) - 1
i = 0
j = 0

while h >= 0:
    while Sum_A[h] + Sum_B[i] <= K:
        j = max(j,h + i)
        if i == len(Sum_B) - 1:
            break
        i += 1
    if h == 0:
        break
    h -= 1

print(j)

Solution (Python):
import numpy as np
from bisect import bisect_right

N, M, K = map(int, input().split())
A: np.ndarray = np.array([0] + list(map(int, input().split())))
B: np.ndarray = np.array([0] + list(map(int, input().split())))

if A.sum() + B.sum() <= K:
    print(N + M)
    exit()

A_cumsum = A.cumsum()
B_cumsum = B.cumsum()




ans = 0
for i in range(N + 1):
    A_time = A_cumsum[i]
    if A_time > K:
        continue
    j = bisect_right(B_cumsum, K - A_time) - 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()))

wa = 0
anslist = []
a_index = 0 
b_index = 0 

for i in range(n+1):
  if i < n and k >= wa + a[i]:
    wa +=a[i]
    anslist.append(i+1)
  else:
    a_index = i
    break

for i in range(m+1):
  if i < m and k >= wa + b[i]:
    wa +=b[i]
    anslist.append(i + 1 + a_index)
  else:
    b_index = i
    break

for _ in range(m):
  if a_index !=0:
    wa -=a[a_index - 1] 
    a_index -=1
  while b_index < m and k >= wa + b[b_index] :
    wa +=b[b_index]
    b_index +=1
  anslist.append(a_index + b_index)
print(max(anslist))

Solution (Python):
import sys
from collections import deque
sys.setrecursionlimit(2147483647)
input=sys.stdin.readline

def main():
  N, M, K = map(int, input().split(' '))
  A = list(map(int, input().split(' ')))
  B = list(map(int, input().split(' ')))
  As = [0]
  Bs = [0]
  for i in range(len(A)):
    As.append(A[i] + As[i])
  for i in range(len(B)):
    Bs.append(B[i] + Bs[i])
  ans, i = 0, N
  for j in range(M+1):
    if(K < Bs[j]):
      break
    while(i >= 0 and K < Bs[j] + As[i]):
      i -= 1
    ans = max(ans, i+j)
  print(ans)

if __name__=='__main__':
  main()

Solution (Python):
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

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

ac = [0]
bc = [0]

for i in range(N):
    ac.append(ac[i] + A[i])
for i in range(M):
    bc.append(bc[i] + B[i])

ans = 0
j = M

for i in range(N+1):
    if ac[i] > K:
        break
    while bc[j] > K - ac[i]:
        j -= 1
    ans = max(ans, i+j)
        
print(ans)

Solution (Python):
from collections import deque

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

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

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

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

print(mx)

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

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

cumA = [0] * (N+1)
cumB = [0] * (M+1)

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

def check(X):
    res = 1e9+1
    for i in range(N+1):
        j = X - i
        if j < 0 or M < j: continue
        if(cumA[i] + cumB[j] < res):
            res = cumA[i] + cumB[j]
    return res <= K

ok = 0
ng = N + M + 1

while ng - ok > 1:
    mid = (ok + ng) // 2
    if(check(mid)): ok = mid
    else: ng = mid

print(ok)

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

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

cumA = [0] * (N+1)
cumB = [0] * (M+1)

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

def check(X):
    res = 1e9+1
    for i in range(N+1):
        j = X - i
        if j < 0 or M < j: continue
        if(cumA[i] + cumB[j] < res):
            res = cumA[i] + cumB[j]
    return res <= K

ok = 0
ng = N + M + 1

while ng - ok > 1:
    mid = (ok + ng) // 2
    if(check(mid)): ok = mid
    else: ng = mid

print(ok)

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

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

p = n
for i in range(n + 1):
    if C[i] > k:
        p = i - 1
        break

_max = p
keep = 0
for i in range(p, -1, -1):
    for j in range(keep, m + 1):
        if C[i] + D[j] > k:
            keep = j - 1
            break
        elif _max < i + j:
            _max = i + j
    if j == m:
        break
print(_max)

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

t = sum(b)
j = m
ans = 0
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()))
A_=[0]
B_=[0]
t=0
for i in A:
    t+=i
    A_.append(t)
t=0
for j in B:
    t+=j
    B_.append(t)
for n in range(N+1):
    if A_[n]>K:
        n-=1
        break

ans=n
t=0
for i in range(n,-1,-1):
    for m in range(t,M+1):

        if B_[m] > K-A_[i]:
            m-=1
            break
    t=m

    ans=max(ans,i+t)
print(ans)

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

p, q = [0], [0]
for i in range(n):
	p.append(p[i] + a[i])
for i in range(m):
	q.append(q[i] + b[i])

j, ans = m, 0
for i in range(n+1):
	if p[i] > k:
		break

	while q[j] > k - p[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()))

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


sum_a = sum(A)

sum_b = 0

b_next_ind = 0

ans = 0


for i in reversed(range(N + 1)):
	
	sum_b_max = K - sum_a
	
	if sum_b_max >= 0:
		
		
		
		
		while b_next_ind < M and sum_b + B[b_next_ind] <= sum_b_max:
			sum_b += B[b_next_ind]
			b_next_ind += 1
		
		
		
		ans = max(ans, i + b_next_ind)
	
	
	
	if i > 0:
		sum_a -= 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()))

sum_a = sum(A)
sum_b = 0
b_next_ind = 0
ans = 0


for i in range(N + 1):
	sum_b_max = K - sum_a
	if sum_b_max >= 0:
		while b_next_ind < M and sum_b + B[b_next_ind] <= sum_b_max:
			sum_b += B[b_next_ind]
			b_next_ind += 1
		ans = max(ans, (N - i) + b_next_ind)
	sum_a -= A[N - 1 - i]

print(ans)

Solution (Python):
from itertools import groupby, accumulate, product, permutations, combinations
def solve():
    ans = 0
    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 = [0]+list(accumulate(B))
    b = M
    for a in range(N+1):
        if A[a]>K:
            break
        while A[a]+B[b]>K:
            b -= 1
        ans = max(a+b,ans)
    return ans
print(solve())

Solution (Python):
'''
a = a1 + a2 + a3 ・・・ai
b = b1 + b2 + b3 ・・・bj
a + b <= K なれば良い
そして、本の数の最大数を求めるから、
つまり、i + j の最大の値を求める

１，まず、考えられる解法が全検索である。
しかし、N=M=200000 の場合には間に合わない。

２，次にiについてのみ考える。
i = 0,1・・・N
そして、bj <= K-ai
であるようなjの最大値を求める。

i=0 のときのjの最大値は、 j = M, M-1 
このように降順に走査すると、最初に bj <= K-ai 左の式が成立したjを求める。
このjをbest0とする

i=1 のときに選択可能なjの最大値を求める。
この最大値はbest0以下であるため、ｊ＝best0から始めることができる
'''
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

'''
aのリストは低い数字からみて、bのリストは高い数字から見る
i=0 のときのjの最大値は、 j = M, M-1 
このように降順に走査すると、最初に bj <= K-ai 左の式が成立したjを求める。
このjをbest0とする

i=1 のときに選択可能なjの最大値を求める。
この最大値はbest0以下であるため、ｊ＝best0から始めることができる
'''



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

i=0
j=m
ans=0
tmp=0
while(i<n+1 and j>=0):
    if(k>=A[i]):
        tmp=k-A[i]
        if(tmp-B[j]>=0):
            ans=max(ans,i+j)
            i+=1
        else:
            j-=1
    else:
        break
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]
B=[0]
for i in range(n):
    A.append(a[i]+A[i])
for j in range(m):
    B.append(b[j]+B[j])

i=0
j=m
ans=0
tmp=0
while(i<n+1 and j>=0):
    if(k>=A[i]):
        tmp=k-A[i]
        if(tmp-B[j]>=0):
            ans=max(ans,i+j)
            i+=1
        else:
            j-=1
    else:
        break
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):
i = list(map(int, input().split()))
n,m,k = i[0], i[1], i[2]

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):
from bisect import bisect_right
from itertools import accumulate

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

a_ac=[0]+list(accumulate(a))
b_ac=[0]+list(accumulate(b))

ans=0
for i in range(n+1):
  remain=k-a_ac[i]
  if remain<0:
    break
  t_ans=i
  t_ans+=bisect_right(b_ac,remain)-1
  ans=max(ans,t_ans)

print(ans)

Solution (Python):
from bisect import bisect_right
from itertools import accumulate

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

a_ac=[0]+list(accumulate(a))
b_ac=[0]+list(accumulate(b))

ans=0
for i in range(n+1):
  remain=k-a_ac[i]
  if remain<0:
    continue
  t_ans=i
  t_ans+=bisect_right(b_ac,remain)-1
  ans=max(ans,t_ans)

print(ans)

Solution (Python):
from bisect import bisect_right
from itertools import accumulate

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

a_ac=[0]+list(accumulate(a))
b_ac=[0]+list(accumulate(b))

ans=0
for i in range(n+1):
  remain=k-a_ac[i]
  if remain<0:
    continue
  t_ans=i
  t_ans+=bisect_right(b_ac,remain)-1
  ans=max(ans,t_ans)

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_ac=[0]
for i in range(1,n+1):
  a_ac.append(a_ac[i-1]+a[i-1])

b_ac=[0]
for i in range(1,m+1):
  b_ac.append(b_ac[i-1]+b[i-1])




ans=0
for i in range(n+1):
  remain=k-a_ac[i]
  if remain<0:
    continue
  t_ans=i
  t_ans+=bisect_right(b_ac,remain)-1
  ans=max(ans,t_ans)

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_ac=[0]
for i in range(1,n+1):
  a_ac.append(a_ac[i-1]+a[i-1])

b_ac=[0]
for i in range(1,m+1):
  b_ac.append(b_ac[i-1]+b[i-1])




ans=0
for i in range(n+1):
  remain=k-a_ac[i]
  if remain<0:
    continue
  t_ans=i
  t_ans+=bisect_right(b_ac,remain)-1
  ans=max(ans,t_ans)

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):
import bisect
N, M, K = 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(1, N+1):
    a[i] = a[i-1] + A[i-1]
for j in range(1, M+1):
    b[j] = b[j-1] + B[j-1]

ans = 0

for i in range(N+1):


    if K - a[i] < 0:
        break










    j = bisect.bisect_right(b, K - a[i]) - 1
    ans = max(ans, i + j)
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()))
a = [0]*(N+1)
b = [0]*(M+1)


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

ans = 0

for i in range(N+1):


    if K - a[i] < 0:
        break










    j = bisect.bisect_right(b, K - a[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()))

sa = [0]
sb = [0]

for i in range(n):
    sa.append(sa[i]+a[i])

for i in range(m):
    sb.append(sb[i]+b[i])

ans = 0
j = m


for i in range(n+1):
    if sa[i] > k:
        break
    while sa[i]+sb[j] > k:
        j -= 1
    ans = max(ans, i+j)

print(ans)

Solution (Python):

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


acum=[0]
bcum=[0]

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

for i in range(m):
    bcum.append(bcum[i]+bl[i])
ans=0;j=m
for i in range(n+1):
    if acum[i]>k:
        break
    while acum[i]+bcum[j]>k:
        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()))






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

B_wa = [0]
for i in range(M) :
    B_wa.append(B_wa[i]+B[i])

a = N
ans = 0
for b in range(M+1):
  A_lim = K - B_wa[b]
  if A_lim < 0:
    break
  while A_wa[a] > A_lim and a > 0:
    a -= 1
  ans = max(a + b, ans)
print(ans)

Solution (Python):
from bisect import *

N,M,K,*f = map(int, open(0).read().split())
A = f[:N]
B = f[N:]
csa = [0]
ans = 0
for i in range(N):
    csa.append(csa[i]+A[i])
csb = [0]
for i in range(M):
    csb.append(csb[i]+B[i])
for i in range(N+1):
    if csa[i] <= K:
        bs = bisect_right(csb,K-csa[i])
        ans = max(ans,i+bs-1)
    else:
        break
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,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, 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, b_cnt = 0, M
for a_cnt in range(N+1):
    if A[a_cnt] > K:
        continue
    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())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))

acum1 = [0]
for i in range(n):
    acum1.append(acum1[-1] + arr1[i])
acum2 = [0]
for i in range(m):
    acum2.append(acum2[-1] + arr2[i])

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

Solution (Python):


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N, M, K = read_ints()
    A = read_ints()
    B = read_ints()
    A_read = 0
    B_read = M
    B_sum = sum(B)
    A_sum = 0
    max_read = 0
    for A_read in range(N+1):
        if A_read > 0:
            A_sum += A[A_read-1]
        while B_read > 0 and A_sum+B_sum > K:
            B_read -= 1
            B_sum -= B[B_read]
        if A_sum+B_sum <= K:
            max_read = max(max_read, A_read+B_read)
    return max_read


if __name__ == '__main__':
    print(solve())

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)