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 math
import sys

sys.setrecursionlimit(10 ** 9)


def binary_research(start, end,function):
    if start == end:
        return start
    middle = math.ceil((start + end) / 2)
    if function(middle, k, a_sum, b_sum):
        start = middle
    else:
        end = middle - 1
    return binary_research(start, end, function)




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()]
a_sum = [0]
b_sum = [0]
for book in a:
    a_sum.append(a_sum[-1] + book)
for book in b:
    b_sum.append(b_sum[-1] + book)


def can_read(num, k, a_sum, b_sum):
    min_read_time = 1000000000000
    for i in range(max(0, num - m), min(num+1,n+1)):
        a_num = i
        b_num = num - i
        min_read_time = min(min_read_time, a_sum[a_num] + b_sum[b_num])
    if min_read_time <= k:
        return True
    return False


start = 0
end = n + m

print(binary_research(start, end, can_read))

Solution (Python):
from itertools import accumulate
from bisect import bisect
n, m, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))
a = list(accumulate(a))
b = list(accumulate(b))
ans = 0
for i in range(n+1):
    if a[i] > k:
        break
    ans = max(ans, i+bisect(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()))
a = [0]
b = [0]
p = 0
for i in range(N):
  p += A[i]
  a.append(p)
q = 0
for j in range(M):
  q += B[j]
  b.append(q)
ans = 0
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):
from itertools import accumulate

n,m,k=map(int,input().split())
a_acum=list(accumulate(list(map(int,input().split()))))
b_acum=list(accumulate(list(map(int,input().split()))))

def ask_number(data,value):
    start,end=0,len(data)
    while True:
        mid=(start+end)//2
        if start == mid:
            break
        if data[mid] > value:
            end=mid
        else:
            start=mid
    if start == 0 and data[0] > value:
        return 0
    else:
        return end
    
ans=ask_number(b_acum,k)

for i in range(n):
        sub = k - a_acum[i]
        if sub < 0:
            break
        else:
            ans=max(ans,ask_number(b_acum,sub)+i+1)
print(ans)

Solution (Python):
n, m, k = [int(i) for i in input().split()]
a = [0] + [int(i) for i in input().split()]
b = [0] + [int(i) for i in 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]
cnt, cnt_ = 0, 0
for i in range(n+1):
  if a[i] <= k:
    cnt = i
for j in range(m+1):
  if b[j] + a[cnt] <= k:
    cnt_ = j
ans = cnt + cnt_
for i in range(cnt):
  for j in range(cnt_, m+1):
    if a[cnt - i - 1] + b[j] > k:
      cnt_ = j
      break
    else:
      ans = max(ans, cnt - i - 1 + 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,ai,bi = 0,0,0
for i in range(n+1):
  if a[i]<=k:
    ai = i
for j in range(m+1):
  if a[ai]+b[j]<=k:
    bi = j
ans = ai+bi
for i in range(ai):
  for j in range(bi,m+1):
    if a[ai-i-1]+b[j]>k:
      bi = j
      break
    else:
      ans = max(ans,ai-i-1+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,bi = 0,m
for i in range(n+1):
  for j in range(bi,-1,-1):
    if a[i]+b[j]<=k:
      ans = max(ans,i+j)
      bi = j
      break
print(ans)

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

At = [0]*(N+1)
Bt = [0]*(M+1)

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

j = M
ans = 0
for i in range(N+1):
  if At[i] > K:
    break
  while At[i] + Bt[j] > K:
    j = j - 1
  if ans < i + j:
  	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 = list(map(int, input().split()))
b = list(map(int, input().split()))
a_rui = [0]
b_rui = [0]
counta = 0
countb = 0
for i in range(n):

    a_rui.append(a_rui[i]+a[i])
    if a_rui[i+1] <= k:
        counta = i+1

for i in range(m):
    b_rui.append(b_rui[i]+b[i])
    if b_rui[i] <= k:
        countb = i+1



ans = 0
for i in range(counta+1):
    
    
    while a_rui[i]+b_rui[countb] > k:
        
        countb -= 1
    
    ans = max(ans, i+countb)
print(ans)

Solution (Python):
import itertools

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

asum = list(itertools.accumulate(a))
bsum = list(itertools.accumulate(b))

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

print(ans)

Solution (Python):

import sys
input = sys.stdin.readline

n,m,k = map(int,input().split())
an = list(map(int,input().split()))
bn = list(map(int,input().split()))

suma = [0]
sumb = [0]
a = 0
b = 0
for i in an:
    a += i
    suma.append(a)
for i in bn:
    b += i
    sumb.append(b)

res = [0]
l = m
for j in range(n+1):
    if k-suma[j] < 0:
        break
    while k-suma[j]-sumb[l] < 0 and l > 0:
        l -= 1
    res.append(j+l)
print(max(res))

Solution (Python):

n,m,k = map(int,input().split())
an = list(map(int,input().split()))
bn = list(map(int,input().split()))

suma = [0]
sumb = [0]
a = 0
b = 0
for i in an:
    a += i
    suma.append(a)
for i in bn:
    b += i
    sumb.append(b)

res = [0]
l = m
for j in range(n+1):
    if k-suma[j] < 0:
        break
    while k-suma[j]-sumb[l] < 0 and l > 0:
        l -= 1
    res.append(j+l)
print(max(res))

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

ans = 0
j = m
for i in range(n+1):
  if acc1[i] > k:
    break
  while acc2[j] > k - acc1[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):
N, M, K = map(int, input().split())
INF = int(1e18)
A = list(map(int, input().split()))
B = list(map(int, input().split()))
i, j = 0, 0
mcnt = 0
tmp = M+1
ccnt = 0
while tmp != 0:
  ccnt += 1
  tmp //= 2
LA = [0 for _ in range(N+1)]
LB = [0 for _ in range(M+1)]
for i in range(N):
  LA[i+1] = LA[i] + A[i]
for i in range(M):
  LB[i+1] = LB[i] + B[i]
for i in range(N+1):
  l, r = 0, M+1
  d = (l + r) // 2
  if LA[i] <= K:
    if LB[M] + LA[i] <= K:
      mcnt = max(i + M, mcnt)
    else:
      for j in range(ccnt + 1):
        if LB[d] + LA[i] <= K:
          l = d
          d = (l + r) // 2
        else:
          r = d
          d = (l + r) // 2
      mcnt = max(i + d, mcnt)
  else:
    break
print(mcnt)

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

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

Solution (Python):
def judge(num):
  if num>n+m:
    return False
  for i in range(max(0,num-m),min(n,num)+1):
    if a_cumsum[i] + b_cumsum[num-i]<=k:
      return True
  return False
 
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
 
a_cumsum = [0]
b_cumsum = [0]
for i in a:
  a_cumsum.append(a_cumsum[-1]+i)
for i in b:
  b_cumsum.append(b_cumsum[-1]+i)
  
left = 0
right = k+1
 
while right-left>1:
  mid = (right+left)//2
  
  if judge(mid):
    left = mid
  else:
    right = mid
 
print(left)

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]

ans = 0
j = m

for i in range(n+1):
    if A[i] > k:
        continue

    while A[i] + B[j] > k:
        j -= 1

    ans = max(ans,j+i)

print(ans)

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

print(answer)

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

print(answer)

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]
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 and b_cnt >= 0:
        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()))

sum_A = [0] * (N + 1)
sum_B = [0] * (M + 1)

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

count = 0



last_index = M

for a in range(len(sum_A)):
    
    
    if sum_A[a] > K:
        count = max(count, a - 1)
        break
    elif sum_A[a] == K:
        count = max(count, a)
    now = sum_A[a]
    rest = K - now
    
    

    while True:
        if last_index < 0:
            able = 0
            break
        if sum_B[last_index] > rest:
            last_index -= 1
        else:
            able = last_index
            break

    
    
    count = max(count, a + able)
    

print(count)

Solution (Python):
import bisect

n, m, k = map(int, input().split())
alist = list(map(int, input().split()))
blist = list(map(int, input().split()))

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

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

x = bisect.bisect_right(alist, k)
ans = bisect.bisect_right(blist, k)
for i in range(x):
    d = k - alist[i]
    y = bisect.bisect_right(blist, d) + i + 1
    if ans < y:
        ans = y

print(ans)

Solution (Python):
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
idx_B = M-1
m = sum(B)
an = M
ans = 0
for a in [0] + A:
    m += a
    while idx_B >= 0 and m > K:
        m -= B[idx_B]
        idx_B -= 1
        an -= 1
    if m > K:
        break
    if an > ans:
        ans = an
    an += 1
print(ans)

Solution (Python):
def getIntList(strList):
  return list(map(lambda x: int(x), strList))

N, M, K = getIntList(input().split(" "))
A = getIntList(input().split(" "))
B = getIntList(input().split(" "))

ta = 0
tb = 0
TA = [0]
TB = [0]

for i in range(len(A)):
  ta += A[i]
  if ta <= K:
    TA.append(ta)
  else:
    break
for j in range(len(B)):
  tb += B[j]
  if tb <= K:
    TB.append(tb)
  else:
    break

Cij = [0]

j = len(TB) - 1
for i in range(len(TA)):
  while TA[i] + TB[j] > K:
    j += -1
  else:
    if j >= 0:
      Cij.append(i + j)
  if j == -1:
    break


print(max(Cij))

Solution (Python):
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
sa=[]
sma=0
for i in range(n):
    sma+=a[i]
    sa.append(sma)
sb=[]
smb=0
for i in range(m):
    smb+=b[i]
    sb.append(smb)
import bisect
lain=bisect.bisect_right(sa,k)-1
if lain<0:
    sm=0
else:
    sm=sa[lain]
stin=bisect.bisect_right(sb,k-sm)-1

if lain<0:
    print(stin+1)
    exit()
if stin>=m-1:
    print(lain+1+m)
    exit()
am=lain+1+stin+1
mx=am
for i in range(lain,-1,-1):
    sm-=a[i]
    am-=1
    while sm+sb[stin+1]<=k:
        stin+=1
        am+=1
        if stin>=m-1:
            print(max(mx,am))
            exit()
    mx=max(mx,am)
print(mx)

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])
maxn = 0
j = m
for i in range(n+1):
  if sa[i] <= k:
    while sa[i] + sb[j] > k:
      j -= 1
    maxn = max(maxn,i+j)
print(maxn)

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

def binary_search(func, array, left=0, right=-1):
    if right==-1:right=len(array)-1
    y_left, y_right = func(array[left]), func(array[right])
    while True:
        middle = (left+right)//2
        y_middle = func(array[middle])
        if y_left==y_middle: left=middle
        else: right=middle
        if right-left==1:break

    return left

cumA = [0]
for i in range(N):
  cumA.append(cumA[-1]+A[i])
  
cumB = [0]
for i in range(M):
  cumB.append(cumB[-1]+B[i])
cumB.append(10**20)
  
if cumA[-1]+cumB[-1]<=K:
  print(N+M)
  exit()
  
if A[0] > K and B[0] > K:
  print(0)
  exit()
  
ans = 0
for i in range(N+1):
  if K-cumA[i]<0:break
  idx = binary_search(lambda x:x<=K-cumA[i],cumB)
  res = max(0,i+idx)
  ans = max(ans, res)
  
print(ans)

Solution (Python):

import sys
from itertools import chain
from bisect import bisect_right





def solve(N: int, M: int, K: int, A: "List[int]", B: "List[int]"):
    A = [0] + A
    for i in range(1, N + 1):
        A[i] = A[i] + A[i - 1]
    B = [0] + B
    for i in range(1, M + 1):
        B[i] = B[i] + B[i - 1]

    answer = 0
    for n in range(N+1):
        ka = A[n]
        if ka > K:
            break
        kb = K - ka  
        m = bisect_right(B, kb) - 1
        if n + m > answer:
            answer = n + m

    return answer


def main():
    tokens = chain(*(line.split() for line in sys.stdin))
    
    N = int(next(tokens))  
    M = int(next(tokens))  
    K = int(next(tokens))  
    A = [int(next(tokens)) for _ in range(N)]  
    B = [int(next(tokens)) for _ in range(M)]  
    answer = solve(N, M, K, A, B)
    print(answer)


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()))
ans = 0
t = sum(B)
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_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]
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 and b_cnt >= 0:
        b_cnt -= 1
    rst = max(rst, a_cnt + b_cnt)
print(rst)

Solution (Python):
n,m,k=map(int,input().split())
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
ar=[0]
br=[0]
for i in range(n):
  ar.append(ar[i]+a[i])
for i in range(m):
  br.append(br[i]+b[i])

ans=0
j=0
cnt=0


for i in range(n+1):
  now=ar[i]
  cnt=i
  nokori=k-now

  if nokori<0:
    continue

  while(br[j]<=nokori):
    if j<m:
      j+=1
    else:
      break
    
  if nokori<br[j]:
    j-=1


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

Solution (Python):
def solve():
    N,M,K = [int(i) for i in input().split()]

    A = [int(i) for i in input().split()]
    cumulative_A = [0] * (len(A)+1)
    for i in range(1, len(cumulative_A)):
        cumulative_A[i] = cumulative_A[i-1] + A[i-1]

    B = [int(i) for i in input().split()]
    cumulative_B = [0] * (len(B)+1)
    for i in range(1, len(cumulative_B)):
        cumulative_B[i] = cumulative_B[i-1] + B[i-1]

    max_j = len(cumulative_B) - 1
    ans = 0
    for i in range(len(cumulative_A)):
        time_A = cumulative_A[i]
        time_B = K - time_A
        is_found = False
        for j in reversed(range(max_j+1)):
            if cumulative_B[j] <= time_B:
                is_found = True
                break
        if is_found:
            cnt = i + j
            ans = max(cnt, ans)
        max_j = j

    print(ans)

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


sum_a = [0]
for i in range(n):
    sum_a.append(sum_a[i] + a[i])

sum_b = [0]
for i in range(m):
    sum_b.append(sum_b[i] + b[i])


a_i = 0
b_i = 0
for i in range(n+1):
    if sum_a[i] > k:
        break
    else:
        a_i = i

for i in range(m+1):
    if sum_a[a_i] + sum_b[i] > k:
        break
    else:
        b_i = i


ans = a_i + b_i
for i in range(a_i, -1, -1):
    for j in range(b_i, m+1):
        if sum_a[i] + sum_b[j] > k:
            b_i = j - 1
            break
        else:
            ans = max(ans, i+j)

print(ans)

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

best = 0
a_time = 0
b_time = sum(B)
b_i = len(B)-1
end_flag = False
for a_i in range(N+1):
    a_time += A[a_i]
    while a_time + b_time > K:
        if b_i == 0:
            end_flag = True
            break
        b_time -= B[b_i]
        b_i -= 1

    if end_flag == True:
        break
    if a_i + b_i > best:
        best = a_i + b_i

print(best)

Solution (Python):
N, M, K = map(int, input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

total = 0
Asum = sum(A)
nA = len(A)
Bsum = 0
ans = 0
for nB in range(len(B) + 1):
    if nB != 0:
        Bsum += B[nB-1]
    if Bsum > K:
        break
    while Asum + Bsum > K:
        nA -= 1
        Asum -= A[nA]
    ans = max(nA + nB, ans)

print(ans)

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]
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 and b_cnt >= 0:
        b_cnt -= 1
    rst = max(rst, a_cnt + b_cnt)
print(rst)

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

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


ans = 0
for i in range(N+1):
    book_count = i
    remain_time = K - A_sum[i]

    ok = 0
    ng = M

    if remain_time >= B_sum[M]:
        ans = book_count + M

    while ng - ok > 1:
        mid = (ok+ng)//2
        if remain_time >= B_sum[mid]:
            ok = mid
        else:
            ng = mid

    book_count += ok
    if remain_time >= 0:
        if book_count > ans:
            ans = book_count


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])
    
v,j=0,M

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

print(v)

Solution (Python):
import sys
import math
import itertools
import collections
from collections import deque

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

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

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

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


if __name__ == '__main__':
    main()

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_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]
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 and b_cnt >= 0:
        b_cnt -= 1
    rst = max(rst, a_cnt + b_cnt)
print(rst)

Solution (Python):
def is_ok(arg):
    return not Alist[arg] <= t
    

def bisect(ok, ng):
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok

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

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

ans = 0
for i in range(N+1):
    if Alist[i] <= K:
        ans = i
    else:
        break

b = 0
for i in range(M):
    b += B[i]
    t = K - b

    if t >= 0:
        res = bisect(N + 1, -1)
        ans = max(ans, i + res)

    else:
        break

print(ans)

Solution (Python):

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

import itertools
A_acum=list(itertools.accumulate(A_list))
B_acum=list(itertools.accumulate(B_list))
A_acum.insert(0, 0)
B_acum.insert(0, 0)


"""
A_acum=[0]
B_acum=[0]
for i in range(1, N+1):
	A_acum[i]=A_acum[i-1]+A_list[i-1]
for j in range(1, M+1):
	B_acum[i]=B_acum[i-1]+B_list[i-1]
"""
ans=0
j=M
for i in range(len(A_acum)): 
	if K<A_acum[i]:
		break
	res = K - A_acum[i] 

	while res<B_acum[j] and j>0:
		j-=1

	ans=max(ans, i+j)

print(ans)

Solution (Python):
from itertools import accumulate
import bisect

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

max_count = 0
for i in range(N + 1):
    a_count = i
    b_count = bisect.bisect_right(SB, K - SA[a_count]) - 1
    if b_count >= 0:
        count = a_count + b_count
        if count > max_count:
            max_count = count
        
print(max_count)

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

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

Solution (Python):
a,b,money=list(map(int,input().split()))
A=[0]+list(map(int,input().split()))
B=[0]+list(map(int,input().split()))
for i in range(1,a+1):
  A[i]+=A[i-1]
for j in range(1,b+1):
  B[j]+=B[j-1]
ans=0
b_cnt=b
for a_cnt in range(a+1):
  if A[a_cnt]>money:
    continue
  while A[a_cnt]+B[b_cnt]>money:
    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()))

A_cumsum, B_cumsum = [0], [0]

for i in range(n):
    A_cumsum.append(A_cumsum[i] + A[i])
    
for j in range(m):
    B_cumsum.append(B_cumsum[j] + B[j])
    
ans, j = 0, m

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

print(ans)

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

    total = 0
    a_index = 0
    b_index = 0
    while a_index != len(A):
        if total + A[a_index] <= k:
            total += A[a_index]
            a_index += 1
        else:
            break
    
    
    while b_index != len(B):
        if total + B[b_index] <= k:
            total += B[b_index]
            b_index += 1
        else:
            break

    
    ans = a_index + b_index 
    a_index -= 1
    while a_index != -1:
        total -= A[a_index]
        a_index -= 1
        while b_index != len(B):
            if total + B[b_index] <= k:
                total += B[b_index]
                b_index += 1
            else:
                break

        if ans < a_index + 1 + b_index :
            ans = a_index + 1 + b_index

    print(ans)



    


if __name__ == '__main__':
    main()

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]
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 and b_cnt >= 0:
        b_cnt -=1
    rst = max(rst, a_cnt + b_cnt)
print(rst)

Solution (Python):
import sys
import bisect
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))

n, m, k = inm()
a = inl()
b = [0] + inl()
count = 0
prev = 0
for i in range(n-1):
    a[i+1] += a[i]
for i in range(m+1):
    if b[i]+prev > k:
        break
    j = bisect.bisect(a, (k - b[i] - prev))
    count = max(count, i + j)
    prev += b[i]
print(count)

Solution (Python):
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

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


def get_nums_l():
    return [ int(s) for s in input().split(" ")]


def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

def main():
    INF = 999999999999999999999999
    MOD = 10**9+7

    n,m,k = get_nums_l()
    A = get_nums_l()
    B = get_nums_l()

    ruisekiA = [0] * (n+1)
    ruisekiB = [0] * (m+1)
    for i in range(n):
        ruisekiA[i+1] = ruisekiA[i] + A[i]
    for i in range(m):
        ruisekiB[i+1] = ruisekiB[i] + B[i]

    ans = 0

    
    for i in range(n+1):

        if ruisekiA[i] > k:
            
            continue

        
        
        l = 0
        
        r = m+1

        while l+1 < r:
            c = (l+r) // 2

            
            if ruisekiA[i] + ruisekiB[c] <= k:
                l = c
            else:
                r = c
        
        ans = max(ans, i+l)

    print(ans)

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

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

s = [0] * (n + 1)
t = [0] * (m + 1)
for i in range(n):
    s[i+1] = s[i] + a[i]
for i in range(m):
    t[i+1] = t[i] + b[i]

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

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