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 os
import operator
from collections import defaultdict
import sys
from io import BytesIO, IOBase
import bisect










def main():
    n,m,k=map(int,input().split())
    A=[int(k) for k in input().split()]
    B=[int(k) for k in 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])
    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)

    
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        








BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

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

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_sum, b_sum = [0], [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, j = 0, m
for i in range(n+1):
  if a_sum[i] > k:
    break
  while b_sum[j] > k - a_sum[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()))

from bisect import bisect_right
"""
if n>m:
    a, b = b, a
    n, m = m, n
"""
c = [b[0]]
for i in range(1, m):
    c.append(c[-1]+b[i])
a.insert(0,0)
x = 0
result = [0]
for i in range(n+1):
    x += a[i]
    if x > k:
        break
    y = k - x
    z = bisect_right(c, y)
    result.append(z+i)
print(max(result))

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

from bisect import bisect_right
"""
if n>m:
    a, b = b, a
    n, m = m, n
"""
c = [b[0]]
for i in range(1, m):
    c.append(c[-1]+b[i])
a.insert(0,0)
x = 0
result = [0]
for i in range(n+1):
    x += a[i]
    if x > k:
        break
    y = k - x
    z = bisect_right(c, y)
    result.append(z+i)
print(max(result))

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

from bisect import bisect_right
if n>m:
    a, b = b, a
    n, m = m, n
c = [b[0]]
for i in range(1, m):
    c.append(c[-1]+b[i])
a.insert(0,0)
x = 0
result = [0]
for i in range(n+1):
    x += a[i]
    if x > k:
        break
    y = k - x
    z = bisect_right(c, y)
    result.append(z+i)
print(max(result))

Solution (Python):

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

a, b = [0], [0]

for i in range(n):
    a.append(a[i] + a_list[i])
    
for j in range(m):
    b.append(b[j] + b_list[j])
    
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 as np
a,b,k=map(int,input().split())
n=list(map(int,input().split()))
m=list(map(int,input().split()))
n.insert(0,0)
m.insert(0,0)
n=np.array(n)
m=np.array(m)
n=n.cumsum()
m=m.cumsum()
ans=0
j=len(m)-1
for i in range(len(n)):
    if n[i]>k:
        break
    while m[j]>k-n[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]

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

print(res)

Solution (Python):
import bisect
N,M,K = map(int, input().split())
A= list(map(int, input().split()))
B = list(map(int, input().split()))
for i in range(1,len(A)):
    A[i]+=A[i-1]
for i in range(1,len(B)):
    B[i]+=B[i-1]

honn=bisect.bisect(B,K)

for i in range(len(A)):
    s=K-A[i]
    if s>=0:
        
        a=bisect.bisect(B,s)
        
        if i+1+a>honn:
            honn=i+1+a
print(honn)

Solution (Python):

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

asum,bsum=[0],[0]

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

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

Solution (Python):
import collections as cc
import itertools as it
import bisect as bi
I=lambda:list(map(int,input().split()))
n,m,k=I()
a=I()
b=I()
a=[0]+list(it.accumulate(a))
b=[0]+list(it.accumulate(b))
ans=0
for i in range(n+1):
	if k-a[i]<0:
		break
	x=bi.bisect_right(b,k-a[i])
	ans=max(ans,i+x-1)
print(ans)

Solution (Python):
N, M, K = list(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[-1] + A[i])
for i in range(M):
    b.append(b[-1] + 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 = 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 = []
t = 0
for n in map(int, input().split()):
  if t + n > K:
    break
  t += n
  A.append(n)
N = len(A)
A = iter(A[::-1])
diff, top, i = 0, 0, 0
for m in map(int, input().split()):
  if t + m <= K:
    t += m
    diff += 1
  else:
    if i >= N:
      break
    for n in A:
      i += 1
      diff -= 1
      t -= n
      if t + m <= K:
        t += m
        diff += 1
        break
  if diff > top:
    top = diff
print(N+top)

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
import numpy as np
from numba import jit, njit
input = lambda: sys.stdin.buffer.readline().rstrip()

@njit(cache=True)
def main(n,m,k,a,b):
  sa = np.cumsum(a)
  sb = np.cumsum(b)
  rx = 0
  rb = m
  for ra in range(0,n+1): 
    while (sb[rb] + sa[ra]) > k and rb>0 :
      rb-=1
    if (sb[rb] + sa[ra]) <= k:
      rx = max(rx,ra+rb)
  return(rx)

n,m,k = map(int, input().split())
a = np.array([0]+list(map(int, input().split())))
b = np.array([0]+list(map(int, input().split())))
print(main(n,m,k,a,b))

Solution (Python):
import sys
import numpy as np
from numba import jit, njit
input = lambda: sys.stdin.buffer.readline().rstrip()

@njit
def main(n,m,k,a,b):
  sa = np.cumsum(a)
  sb = np.cumsum(b)
  rx = 0
  rb = m
  for ra in range(0,n+1): 
    while (sb[rb] + sa[ra]) > k and rb>0 :
      rb-=1
    if (sb[rb] + sa[ra]) <= k:
      rx = max(rx,ra+rb)
  return(rx)

n,m,k = map(int, input().split())
a = np.array([0]+list(map(int, input().split())))
b = np.array([0]+list(map(int, input().split())))
print(main(n,m,k,a,b))

Solution (Python):
import sys
import numpy as np
from numba import jit, njit
input = lambda: sys.stdin.buffer.readline().rstrip()

@njit
def main(n,m,k,sa,sb):
  rx = 0
  rb = m
  for ra in range(0,n+1): 
    while (sb[rb] + sa[ra]) > k and rb>0 :
      rb-=1
    if (sb[rb] + sa[ra]) <= k:
      rx = max(rx,ra+rb)
  return(rx)

n,m,k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sa = np.cumsum([0]+a)
sb = np.cumsum([0]+b)
print(main(n,m,k,sa,sb))

Solution (Python):
import numpy as np

def main():
  n,m,k=map(int,input().split())
  a=list(map(int,input().split()))
  b=np.array(list(map(int,input().split())))
  b=np.cumsum(b)
  k0=k+1
  b0=np.searchsorted(b,k0)
  r=b0
  i=0
  for i, ia in enumerate(a):
    k0=k0-ia
    if k0<=0:
      break
    b0=np.searchsorted(b,k0)
    b0+=i+1
    if b0 > r:
      r=b0
  print(r)
main()

Solution (Python):
n,m,k = map(int,input().split())
arr0 = list(map(int,input().split()))
arr1 = list(map(int,input().split()))
acc0 = [0]

for i in range(n):
  acc0.append(acc0[-1] + arr0[i])
acc1 = [0]
for i in range(m):
  acc1.append(acc1[-1] + arr1[i])
ans = 0
j = m
for i in range(n+1):
  if acc0[i] > k:
    break
  while acc1[j] > k - acc0[i] and j > 0:
    j -= 1
  ans = max(ans, i + j)

print(ans)

Solution (Python):
import numpy as np
a,b,k=map(int,input().split())
n=list(map(int,input().split()))
m=list(map(int,input().split()))
n.insert(0,0)
m.insert(0,0)
n=np.array(n)
m=np.array(m)
n=n.cumsum()
m=m.cumsum()
ans=0
j=len(m)-1
for i in range(len(n)):
    if n[i]>k:
        break
    while m[j]>k-n[i]:
        j-=1
    ans=max(ans,i+j)
print(ans)

Solution (Python):
from sys import stdin
import bisect

def main():
    input = stdin.readline
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = [0] * (n + 1)
    for i in range(n):
        c[i + 1] = c[i] + a[i]
    d = [0] * (m + 1)
    for i in range(m):
        d[i + 1] = d[i] + b[i]
    cnt = 0
    for i in range(n + 1):
        if c[i] > k:
            break
        e = bisect.bisect_right(d, k - c[i])
        if cnt < i + e - 1:
            cnt = i + e - 1
    print(cnt)
main()

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
ans = 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

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())
costA=list(map(int,input().split()))
costB=list(map(int,input().split()))
costA=[0]+costA
costB=[0]+costB

for i in range(N):
    costA[i+1]+=costA[i]
    
for i in range(M):
    costB[i+1]+=costB[i]

"""print(costA)
print(costB)"""

""

def upper_bound(list1,K):
    low=0
    high=len(list1) 
    while high-low!=1:
        mid=(high+low)//2
        if list1[mid]>K:
            high=mid
        else:
            low=mid
    return low  

number=[]


for i in range(N+1): 
    time=K-costA[i]
    if time<0:
        break
    
    number.append(i+upper_bound(costB,time))

"""print(i)
    print(upper_bound(costB,time))
    print(number)"""
    
print(max(number))



"""
print(cumcost)




    

low=0
high=len(cumcost)-1
while high-low!=1: 
    print(high)
    print(low)
    mid=(high+low)//2 
    if cumcost[mid]>K:  
        high=mid
    else: 
        low=mid 

    
    
upper_bound=high 
print(upper_bound)
"""
"""境界線が端っこにあると上手に探索できない
→例外処理で乗り切るか　探索のやり方自体を変更するか　どちらが良いか？"""

Solution (Python):
import numpy as np
def main():
  n,m,k=map(int,input().split())
  a=np.array(list(map(int,input().split())))
  b=np.array(list(map(int,input().split())))
  a=np.cumsum(a)
  b=np.cumsum(b)
  k+=1
  a0=np.searchsorted(a,k)
  b0=np.searchsorted(b,k)
  if a0>b0:
    r=a0
  else:
    r=b0
  for i in range(a0):
    k0=k-a[i]
    b0=np.searchsorted(b,k0)
    b0+=i+1
    if b0 > r:
      r=b0
  print(r)
main()

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
for a_cnt in range(n+1):
    if A[a_cnt]>k:
        continue
    start=0
    goal=m+1
    while start!=goal:
        b_cnt=(start+goal)//2
        if A[a_cnt]+B[b_cnt]>k:
            goal=b_cnt
        else:
            start=b_cnt+1
            ans=max(ans,a_cnt+b_cnt)
print(ans)

Solution (Python):
n,m,k = list(map(int,input().split()))
aarr = list(map(int,input().split()))
barr = list(map(int,input().split()))
a = 0
ans = n

for i in range(n):
    if a+aarr[i] > k:
        ans = i
        break
    a += aarr[i]

res = ans
num = 0
idx = 0
while res >= 0 and idx < m:
    if a+barr[idx] <= k:
        a += barr[idx]
        idx += 1
        num += 1
        ans = max(ans,res+num)
    elif res == 0:
        break
    else:
        a -= aarr[res-1]
        res -= 1

print(ans)

Solution (Python):
import sys
import numpy as np
input = lambda: sys.stdin.readline().rstrip()

def main():
  n,m,k = map(int, input().split())
  a = list(map(int, input().split()))
  b = list(map(int, input().split()))
  sa = np.cumsum([0]+a)
  sb = np.cumsum([0]+b)
  rx = 0
  rb = m
  for ra in range(0,n+1): 
    while (sb[rb] + sa[ra]) > k and rb>0 :
      rb-=1
    if (sb[rb] + sa[ra]) <= k:
      rx = max(rx,ra+rb)
  print(rx)

if __name__ == '__main__':
    main()

Solution (Python):
import sys
import numpy as np
input = lambda: sys.stdin.readline().rstrip()

def main():
  n,m,k = map(int, input().split())
  a = list(map(int, input().split()))
  b = list(map(int, input().split()))
  sa = np.cumsum([0]+a)
  sb = np.cumsum([0]+b)
  for i in range(n):
    sa[i+1] = sa[i] + a[i]
  for i in range(m):
    sb[i+1] = sb[i] + b[i]
  rx = 0
  rb = m
  for ra in range(0,n+1): 
    while (sb[rb] + sa[ra]) > k and rb>0 :
      rb-=1
    if (sb[rb] + sa[ra]) <= k:
      rx = max(rx,ra+rb)
  print(rx)

if __name__ == '__main__':
    main()

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

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

ans=0
for i in range(n+1):
  idx=0
  if waa[i]>k:
    break
  idx=bisect.bisect_right(wab,k-waa[i])
  ans=max(ans,i+idx-1)
print(ans)

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


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    a = list(accumulate([0] + A))
    b = list(accumulate(B))
    
    
    answer = 0
    for i in range(N + 1):
        k_b = K - a[i]
        if k_b >= 0:
            b_read = bisect(b, k_b)
            
            answer = max(i + b_read, answer)
        else:
            continue

    print(answer)


if __name__ == "__main__":
    main()

Solution (Python):
import sys
import numpy as np
input = lambda: sys.stdin.readline().rstrip()

def main():
  n,m,k = map(int, input().split())
  a = tuple(map(int, input().split()))
  b = tuple(map(int, input().split()))
  sa = [0] * (n+1)
  sb = [0] * (m+1)
  for i in range(n):
    sa[i+1] = sa[i] + a[i]
  for i in range(m):
    sb[i+1] = sb[i] + b[i]
  rx = 0
  rb = m
  for ra in range(0,n+1): 
    while (sb[rb] + sa[ra]) > k and rb>0 :
      rb-=1
    if (sb[rb] + sa[ra]) <= k:
      rx = max(rx,ra+rb)
  print(rx)

if __name__ == '__main__':
    main()

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

def main():
  n,m,k = map(int, input().split())
  a = tuple(map(int, input().split()))
  b = tuple(map(int, input().split()))
  sa = [0] * (n+1)
  sb = [0] * (m+1)
  for i in range(n):
    sa[i+1] = sa[i] + a[i]
  for i in range(m):
    sb[i+1] = sb[i] + b[i]
  rx = 0
  rb = m
  for ra in range(0,n+1): 
    while (sb[rb] + sa[ra]) > k and rb>0 :
      rb-=1
    if (sb[rb] + sa[ra]) <= k:
      rx = max(rx,ra+rb)
  print(rx)

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

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


for i in range(1, len(A)):
    A[i] += A[i-1]

for i in range(1, len(B)):
    B[i] += B[i-1]




books_stack_a = 0

books_stack_b = M

cur_max = 0

for books_stack_a in range(0, N + 1):
    if A[books_stack_a] > K:
        break
    diff = K - A[books_stack_a]
    while diff < B[books_stack_b]:
        books_stack_b -= 1

    cur_max = max(cur_max, books_stack_b + books_stack_a)

print(cur_max)

Solution (Python):
import sys
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()))
  sa = [0] * (n+1)
  sb = [0] * (m+1)
  for i in range(n):
    sa[i+1] = sa[i] + a[i]
  for i in range(m):
    sb[i+1] = sb[i] + b[i]
  rx = 0
  rb = m
  for ra in range(0,n+1): 
    while (sb[rb] + sa[ra]) > k and rb>0 :
      rb-=1
    if (sb[rb] + sa[ra]) <= k:
      rx = max(rx,ra+rb)
  print(rx)

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


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
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()))
  sa = [0] * (n+1)
  sb = [0] * (m+1)
  for i in range(n):
    sa[i+1] = sa[i] + a[i]
  for i in range(m):
    sb[i+1] = sb[i] + b[i]
  rx = 0
  rb = m
  for ra in range(0,n+1): 
    while (sb[rb] + sa[ra]) > k and rb>0 :
      rb-=1
    if (sb[rb] + sa[ra]) <= k:
      rx = max(rx,ra+rb)
  print(rx)

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

x = [0]
y = [0]
for i in range(n):
    x.append(x[i] + a[i])
    
for i in range(m):
    y.append(y[i] + b[i])
    
i = 0
j = m
ans = 0
while i <= n and 0 <= j:
    if x[i] + y[j] <= k:
        ans = max(ans, i + j)
        i += 1
    else:
        j -= 1

print(ans)

Solution (Python):
import bisect

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


totaltime_a=[0]
for a in list_a:
    temp_a=totaltime_a[-1]+a
    if temp_a>K:
        break
    else:
        totaltime_a.append(temp_a)

totaltime_b=[0]
for b in list_b:
    totaltime_b.append(totaltime_b[-1]+b)

ans=0

for i in range (len(totaltime_a)):
    Kb=K-totaltime_a[i]
    j=bisect.bisect_right(totaltime_b,Kb)-1
    if i+j>ans:
        ans=i+j
    else:
        pass

print(ans)

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()))
sa = [0] * (n+1)
sb = [0] * (m+1)
for i in range(n):
  sa[i+1] = sa[i] + a[i]
for i in range(m):
  sb[i+1] = sb[i] + b[i]
rx = 0
rb = m
for ra in range(0,n+1): 
  while (sb[rb] + sa[ra]) > k and rb>0 :
    rb-=1
  if (sb[rb] + sa[ra]) <= k:
    rx = max(rx,ra+rb)
print(rx)

Solution (Python):
n,m,k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sa = [0] * (n+1)
sb = [0] * (m+1)
for i in range(n):
  sa[i+1] = sa[i] + a[i]
for i in range(m):
  sb[i+1] = sb[i] + b[i]
rx = 0
rb = m
for ra in range(0,n+1): 
  while (sb[rb] + sa[ra]) > k and rb>0 :
    rb-=1
  if (sb[rb] + sa[ra]) <= k:
    rx = max(rx,ra+rb)
print(rx)

Solution (Python):
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

import bisect
from itertools import accumulate


n,m,k = readints()

a = readints()
b = readints()

c = [0] + list(accumulate(a))
d = [0] + list(accumulate(b))

ans = 0
for i in range(n+1):
    if c[i]>k:
        continue
    else:
        ans = max(ans,i+bisect.bisect_right(d,k-c[i])-1)

print(ans)

Solution (Python):


import itertools
import bisect

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

sum_ = 0
count = 0
for i in range(len(a)):
    if (sum_+a[i]) > k:
        break
    else:
        count += 1
        sum_ += a[i]
a_max = count

sum_ = 0
count = 0
for i in range(len(b)):
    if (sum_+b[i]) > k:
        i = i-1
        break
    else:
        count += 1
        sum_ += b[i]
b_max = count


list_ = list(reversed(a[:a_max])) + b[:b_max]
list_acc = list(itertools.accumulate(list_))


index = bisect.bisect_right(list_acc, k)
ans = index

now_left = 0
now_right = index



while(now_right != len(list_)):
    k += list_[now_left]
    now_left += 1

    while(now_right != len(list_)):
        if list_acc[now_right] <= k:
            now_right += 1
        else:
            break
    
    ans = max(ans, now_right-now_left)

print(ans)

Solution (Python):

'''
尺取り法、二分探索、両方良問なので両方で解けるようにする。
'''
N, M ,K= map(int,input().split())
A = [0] + list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
cnt = []
b_idx = M-1


b_cum = []
cum = 0
for b in B:
    cum += b
    b_cum.append(cum)
a_sum = 0
for i,a in enumerate(A):
    a_sum += a
    if a_sum > K:
        break
    while b_idx >= 0 and a_sum + b_cum[b_idx] > K:
        b_idx -= 1
    ans = max(ans, i + b_idx + 1)
print(ans)

Solution (Python):
import sys

if sys.subversion[0] == "PyPy":
    import io, atexit

    sys.stdout = io.BytesIO()
    atexit.register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))

    sys.stdin = io.BytesIO(sys.stdin.read())
    input = lambda: sys.stdin.readline().rstrip()
RS = raw_input
RA = lambda x=int: map(x, RS().split())
RN = lambda x=int: x(RS())


def solve():
    rm = k
    i = 0
    books_read = 0
    while i<n and rm - a[i] >= 0:
        rm -= a[i]
        books_read += 1
        i += 1
    i -= 1
    max_read = books_read
    j = 0
    while (j<m and i>=0):
        while j < m and rm - b[j] >= 0:
            rm -= b[j]
            books_read += 1
            j += 1
            max_read = max(max_read, books_read)
        rm += a[i]
        i -= 1
        books_read -= 1
        while j<m and rm - b[j] >= 0:
            rm -= b[j]
            books_read += 1
            j += 1
            max_read = max(max_read, books_read)
    print(max_read)

    return




n,m,k = RA()
a = RA()
b = RA()
solve()

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




ans = 0
end = N 



for i in range(M+1):
    A_use = K-B_wa[i]
    if A_use<0: 
        break
    
    
    
    A_MAX = 0
    start = 0
    while  end-start>=1 : 
        now = int((start + end + 1)/2)
        if A_wa[now]==A_use :  
            A_MAX = now 
            break
        elif A_wa[now]<A_use : 
            start = now 
            A_MAX = now 
        else : 
            end = now-1
    
    end=A_MAX 
    
    
    
    if A_MAX+i>ans :
        ans=A_MAX+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]

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 itertools import accumulate
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 = [0] + list(accumulate(A))
b = [0] + list(accumulate(B))

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

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




ans = 0
end = N 

for i in range(M+1):
    A_use = K-B_wa[i]
    if A_use<0: 
        break
    
    
    A_MAX = 0
    start = 0
    while  end-start>=1 : 
        now = int((start + end+1)/2) 
        if A_wa[now]==A_use :  
            A_MAX = now 
            break
        elif A_wa[now]<A_use : 
            start = now 
            A_MAX = now 
        else : 
            end = now-1
    
    
    
    if A_MAX+i>ans :
        ans=A_MAX+i

    end=A_MAX 


print(ans)

Solution (Python):
n,m,k = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
b = sum(B)
ka = k
i = m
c = 0
re = 0
A.insert(0, 0)
for a in A:
  ka -= a
  if ka < 0:
    break
  while ka < b and i > 0:
    i -= 1
    b -= B[i]
  c += 1
  re = max(re, c+i)

  
print(re-1)

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):
  a_sum.append(a[i] + a_sum[i])
b_sum = [0]
for i in range(m):
  b_sum.append(b[i] + b_sum[i])
  
ans = 0
j = m
for i in range(n+1):
  if a_sum[i] > k:
    break
  while a_sum[i] + b_sum[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=[0]
b=[0]

tmp_a=0
tmp_b=0
for i in A:
    tmp_a+=i
    a.append(tmp_a)

for i in B:
    tmp_b+=i
    b.append(tmp_b)
    

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

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

A_cum = [0]
B_cum = [0]

for i in range(n):
  A_cum.append(A_cum[i]+A[i])
  
for i in range(m):
  B_cum.append(B_cum[i]+B[i])

ans = 0  
for i in range(n+1):
  rest = k-A_cum[i]
  if rest<0:
    continue
  
  ans = max(ans, bisect.bisect_right(B_cum, rest)-1+i)
  
print(ans)

Solution (Python):
import bisect
N,M,K=[int(s) for s in input().split()]
A=[int(s) for s in input().split()]
B=[int(s) for s in input().split()]
Asum=[0 for i in range(N+1)]
Bsum=[0 for i in range(M+1)]
for i in range(N):
  Asum[i+1]=Asum[i]+A[i]
for i in range(M):
  Bsum[i+1]=Bsum[i]+B[i]
ans=[0 for i in range(N+1)]
t=bisect.bisect_right(Bsum,K)-1
ans[0]=t
for i in range(1,N+1):
  if Asum[i]>K:
    break
  while Bsum[t]+Asum[i]>K:
    t-=1
  ans[i]=i+t
print(max(ans))