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):
def is_ok(index, key):
    return B[index] <= key

def upper_bound(key): 
    ng = len(B)
    ok = -1

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

n, m, k = map(int, input().split())
tmpA = list(map(int, input().split()))
tmpB = list(map(int, input().split()))
A = [0]
B = [0]

if A:
    for i in range(n):
        tmp = A[i] + tmpA[i]
        if tmp > k:
            break
        else:
            A.append(tmp)
if B:
    for i in range(m):
        tmp = B[i] + tmpB[i]
        if tmp > k:
            break
        else:
            B.append(tmp)

answer = 0
for i in range(len(A)):
    key = k - A[i]
    answer = max(answer, upper_bound(key) + i)

print(answer)

Solution (Python):
N, M, K = map(int, input().split())
 
A = list(map(int, input().split()))
B = list(map(int, input().split()))
 
def solve(A, N, B, M, K):
  
  def cumsum(l):
    rt = [0]
    s = 0
    for n in l:
      s += n
      rt.append(s)
    return rt
  
  preA = cumsum(A)
  preB = cumsum(B)
  
  s, e = 0, N + M
  
  def can_read(num):
    for i in range(N + 1):
      j = num - i
      if j >= 0 and j < (M + 1) and (preA[i] + preB[j]) <= K:
      	return True
    return False

  res = 0
  while s <= e:
    mid = s + (e - s) // 2
    can = can_read(mid)
    
    if can:
      res = mid
      s = mid + 1
    else:
      e = mid - 1
  
  return res

res = solve(A, N, B, M, K)

print(res)

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

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

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

    while lib[j] > k - lia[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 = 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[i] + A_cum[i])
for i in range(M):
    B_cum.append(B[i] + B_cum[i])
    
book = 0
j = M
for i in range(N+1):
    if A_cum[i] > K:
        break
    while A_cum[i] + B_cum[j] > K:
        j -= 1
    book = max(book, i+j)
    
print(book)

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

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

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

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

import numpy as np
import bisect

ra=[0]+list(np.cumsum(a))
rb=[0]+list(np.cumsum(b))

ans=0
for i in range(n+1):    
    capa = k - ra[i]
    if ra[i]>k:
        break
    j=bisect.bisect_right(rb,capa)


    ans=max(ans,i-1+j)
            
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()))
accA = [0]

for Ai in A:
    accA.append(accA[-1]+Ai)

accB = [0]

for Bi in B:
    accB.append(accB[-1]+Bi)

ans = 0
j = M

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

print(ans)

Solution (Python):
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def solve():
    n, m, k = nm()
    a = nl() + [k+1]
    b = nl() + [k+1]
    ai = bi = 0
    als = bs = 0
    while bs + b[bi] <= k:
        bs += b[bi]
        bi += 1
    ans = bi
    for i in range(n+1):
        als += a[i]
        if als > k:
            break
        while bs + als > k:
            bi -= 1
            bs -= b[bi]
        ans = max(ans, i + bi + 1)
    print(ans)
    return

solve()

Solution (Python):
import numpy as np
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline



def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    n, m, k = geta(int)
    a = np.array([0] + list(geta(int)))
    b = np.array([0] + list(geta(int)))

    ca = np.cumsum(a)
    cb = np.cumsum(b)

    ans = 0
    for i, ai in enumerate(ca):
        if k < ai:
            break

        j = np.searchsorted(cb, k-ai, side="right") - 1

        if ans < i + j:
            ans = i + j

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

import numpy as np
import bisect

ra=[0]+list(np.cumsum(a))
rb=[0]+list(np.cumsum(b))

ans=0
for i in range(n+1):    
    capa = k - ra[i]
    if capa<0:
        break
    j=bisect.bisect_right(rb,capa)


    ans=max(ans,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()))
acum1 = [0]
for i in range(N):
    acum1.append(acum1[-1] + A[i])
acum2 = [0]
for i in range(M):
    acum2.append(acum2[-1] + B[i])
ans = 0
j = M
for i in range(N + 1):
    if acum1[i] > K:
        break
    while 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 = [int(x) for x in input().split()]
B = [int(y) for y 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,j = 0,M

for i in range(N+1):
    if a[i] > K:
        break
    while K < a[i] + b[j]:
        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 itertools import accumulate
a=list(accumulate(a))
b=list(accumulate(b))
from bisect import bisect_right
ans=bisect_right(b,k)
for i in range(n):
  if a[i]>k:break
  ans=max(ans,i+1+bisect_right(b,k-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()))

na, nb = [0], [0]
for i in range(n):
    na.append(na[i] + a[i])
for j in range(m):
    nb.append(nb[j] + b[j])

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

P=[0]*(N+1)
Q=[0]*(M+1)

for i in range(1, N+1):
  P[i]=P[i-1]+A[i-1]
  
for i in range(1, M+1):
  Q[i]=Q[i-1]+B[i-1]
  
import bisect
ans=0
for i in range(N+1):
  t=K-P[i]
  if t>=0:
    tmp=i+bisect.bisect_right(Q, t)-1
    ans=max(ans, tmp)
  
print(ans)

Solution (Python):
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))

import numpy as np

def binarySearch(lis,key):
    ng = -1
    ok = len(lis)
    while abs(ok-ng) > 1:
        mid = (ok+ng)//2
        if isOk(lis,mid,key): ok = mid
        else: ng = mid
    return ok

def isOk(lis,index,key):
    if lis[index] > key: return True
    else: return False

n,m,k = iim()
a = iil()
cuma = np.cumsum(a)
b = iil()
cumb = np.cumsum(b)

ans = binarySearch(cumb,k)
for i,item in enumerate(cuma):
    if item > k:
        break

    res = k-item
    plus = binarySearch(cumb,res)
    ans = max(ans,i+1+plus)

print(ans)

Solution (Python):

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

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

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

ans = 0
b_ub = M + 1
for i in range(N + 1):
    rest = K - cum_A[i]
    for j in range(b_ub)[::-1]:
        if cum_B[j] <= rest:
            ans = max(i + j, ans)
            b_ub = j + 1
            break

print(ans)

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

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

ans = 0
b_ub = M + 1
for i in range(N + 1):
    rest = K - cum_A[i]
    for j in range(b_ub)[::-1]:
        if cum_B[j] <= rest:
            ans = max(i + j, ans)
            b_ub = j + 1
            break

print(ans)

Solution (Python):
import sys 
import numpy as np
import bisect
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, M, K = map(int, readline().split())
A = list(map(int,readline().split()))
B = list(map(int,readline().split()))
A_cum = [0] + list(np.cumsum(A))
B_cum = [0] + list(np.cumsum(B))
A_count = bisect.bisect_right(A_cum,K)
ans = 0
for a in range(A_count):
    t = K-A_cum[a]
    b = bisect.bisect_right(B_cum,t)
    b -=1
    ans = max(ans, a+b)
print(ans)

Solution (Python):
import sys
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]

import itertools
import bisect

N, M, K = ri_()
A = [0] + list(itertools.accumulate(ri_()))
B = list(itertools.accumulate(ri_()))
ans = 0
for i in range(N + 1):
    if K - A[i] >= 0:
        j = bisect.bisect_right(B, K - A[i])
        ans = max(ans, i + j)
print(ans)

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

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

A, B = [0], [0]

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

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

ans = 0
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())
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(0, n+1):
    if a[i]>k:
        break
    else:
        while a[i]+b[j]>k:
            j-=1
        
    ans=max(ans, i+j)


print(ans)

Solution (Python):
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))

def binary_search(lis, item):
    low = 0
    high = len(lis) - 1
    inRange = high

    if lis[0] > item:
        return 0

    while low <= high:
        mid = (low + high) //2
        guess1 = lis[mid]
        if mid < inRange:
            guess2 = lis[mid+1]
        else:
            if lis[mid] <= item:
                return len(lis)
            else:
                return len(lis)-1
        if guess1 <= item < guess2:
            return mid+1
        if guess1 > item:
            high = mid-1
        else:
            low = mid+1
    return 0

n,m,k = iim()
a = iil()
cuma = []
if a[0] <= k:
    cuma.append(a[0])
    for i in range(n-1):
        num = cuma[-1]+a[i+1]
        if num > k:
            break
        else:
            cuma.append(num)

b = iil()
cumb = []
if b[0] <= k:
    cumb.append(b[0])
    for i in range(m-1):
        num = cumb[-1]+b[i+1]
        if num > k:
            break
        else:
            cumb.append(num)


ans = len(cumb)

if len(cuma) > 0:
    cnt = len(cuma)
    for i,item in enumerate(cuma[::-1]):
        tmp = cnt-i
        res = k-item
        plus = binary_search(cumb,res)
        ans = max(ans,tmp+plus)
print(ans)

Solution (Python):










import sys

def input(): return sys.stdin.readline()
def iIn(): return int(input())
def iInM(): return map(int, input().split())
def iInM1(): return map(int1, input().split())
def iInLH(): return list(map(int, input().split()))
def iInLH1(): return list(map(int1, input().split()))
def iInLV(n): return [iIn() for _ in range(n)]
def iInLV1(n): return [iIn()-1 for _ in range(n)]
def iInLD(n): return [iInLH() for _ in range(n)]
def iInLD1(n): return [iInLH1() for _ in range(n)]
def sInLH(): return list(input().split())
def sInLV(n): return [input().rstrip("\n") for _ in range(n)]
def sInLD(n): return [sInLH() for _ in range(n)]

def OutH(lst): print(*lst)
def OutV(lst): print(*lst, sep="\n")

sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1

INF = int(1e9)
MOD = 1000000007
dx = (-1, 0, 1, 0)
dy = (0, -1, 0, 1)


N, M, K = iInM()
A = iInLH()
B = iInLH()

a, b = [0], [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
    else:
        while a[i] + b[j] > K:
            j -= 1
        ans = max(ans, i + j)

print(ans)

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

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

j=M
ans=0
for i in range(len(A)+1):

    if(K<a[i]):
        break
    
    while(a[i]+b[j]>K):
        j=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 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 a[i]+b[j]>K:
        j-=1
    ans=max(ans,i+j)
print(ans)

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

if __name__ == '__main__':
  n,m,k=map(int,input().strip("\n").split())
  A=list(map(int,input().strip("\n").split()))
  B=list(map(int,input().strip("\n").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):
import sys
from io import StringIO
import unittest
import os
import bisect


sys.setrecursionlimit(999999999)


def cumsum(target: []):
    result = []
    for cnt, a in enumerate(target):
        result.append(a) if cnt == 0 else result.append(result[cnt - 1] + a)
    return result



def resolve(test_def_name=""):
    n, m, k = map(int, input().split())
    a_s = list(map(int, input().split()))
    b_s = list(map(int, input().split()))

    sum_a_s = [0] + cumsum(a_s)
    sum_b_s = [0] + cumsum(b_s)

    
    
    remain_time_s = []
    for sum_a in sum_a_s:
        if sum_a > k:
            break
        remain_time_s.append(k - sum_a)

    ans = 0
    b_start = 0
    sum_b_s_rev = list(reversed(list(enumerate(sum_b_s))))

    
    for cnt_a, remain_time in enumerate(remain_time_s):
        
        for i in range(b_start, len(sum_b_s_rev)):
            if sum_b_s_rev[i][1] > remain_time:
                b_start += 1
                continue
            ans = max(ans, cnt_a + sum_b_s_rev[i][0])
            break

    print(ans)


class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """3 4 240
60 90 120
80 150 80 150"""
        output = """3"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """3 4 730
60 90 120
80 150 80 150"""
        output = """7"""
        self.assertIO(test_input, output)

    def test_input_3(self):
        test_input = """5 4 1
1000000000 1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000"""
        output = """0"""
        self.assertIO(test_input, output)

    
    def test_origin_1(self):
        test_input = """2 3 100
90 10
10 10 10"""
        output = """3"""
        self.assertIO(test_input, output)



if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        
        resolve()

    else:
        
        unittest.main()

Solution (Python):
from bisect import bisect_right

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

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

ans=0
for i in range(n+1):
    temp=k-sA[i]
    if temp<0:
        break
    add=bisect_right(sB,temp)
    ans=max(ans,i+add)

print(ans)

Solution (Python):
from sys import stdin
import sys
import math
import random
from decimal import Decimal


N, M, K = [int(x) for x in stdin.readline().rstrip().split()]
A = list(map(int, input().split()))
A1 = [0]
for i, v in enumerate(A):
    x = A1[i]+v
    A1.append(x)
B = list(map(int, input().split()))
B1 = [0]
for i, v in enumerate(B):
    x = B1[i]+v
    B1.append(x)
c1 = 0
c2 = 0
ans = 0
temp = M

for i in range(N+1):
    if A1[i] > K:
        break
    while B1[temp] > K-A1[i]:
        temp -= 1
    ans = max(ans, i+temp)
    
    
    
    
    


print(ans)

Solution (Python):
import numpy as np
import bisect

n, m, k = map(int, input().split())
A = [0] + list(map(int,input().split())) 
B = [0] + list(map(int,input().split())) 

a = np.cumsum(A) 
b = np.cumsum(B) 

ans = 0
for i in range(n+1): 
    time = k - a[i] 
    if time < 0: 
        break
    tmp = bisect.bisect_right(b, time) - 1 
    ans = max(ans, tmp + i)

print(ans)

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

a = [0]
b = [0]

for i in range(N):
  a.append(a[i] + AList[i])
for j in range(M):
  b.append(b[j] + BList[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):
import itertools
import bisect

n,m,k=map(int,input().split())
a=[0]+list(map(int,input().split()))
b=list(map(int,input().split()))
aa=list(itertools.accumulate(a))
bb=list(itertools.accumulate(b))
r=0
for i,ax in enumerate(aa):
    bis=bisect.bisect_right(bb,k-ax)
    if bis==0 and ax>k:continue
    r=max(r,i+bis)
print(r)

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

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

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

a = [0] + A
b = [0] + B

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

for i in range(len(b)-1):
    b[i+1] += 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)

Solution (Python):


import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())
from bisect import bisect

def resolve():
    it = map(int, sys.stdin.read().split())
    N, M, K = next(it), next(it), next(it)

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

    ax = min(bisect(A, K), N)
    bx = min(bisect(B, K), M)

    ans = 0
    for i in range(ax+1):
        rest = K - A[i]
        for j in range(bx, -1, -1):
            if B[j] <= rest:
                bx = j
                ans = max(ans, i+j)
                break

    print(ans)


if __name__ == "__main__":
    resolve()

Solution (Python):
import sys
def input():
    return sys.stdin.readline()
N, M, K = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
a = [0] * (N+1)
b = [0] * (M+1)
for i in range(N):
    a[i+1] = a[i] + A[i]
for i in range(M):
    b[i+1] = b[i] + B[i]
ans = 0
j = M
for i in range(N+1):
    tmp = K - a[i]
    if tmp < 0:
        break
    while b[j] > tmp:
        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, = map(int, input().split())
*B, = map(int, input().split())
a = [0] * (N+1)
b = [0] * (M+1)
for i in range(N):
    a[i+1] = a[i] + A[i]
for i in range(M):
    b[i+1] = b[i] + B[i]
ans = 0
j = M
for i in range(N+1):
    tmp = K - a[i]
    if tmp < 0:
        break
    while b[j] > tmp:
        j -= 1
    ans = max(ans, i + j)
print(ans)

Solution (Python):
import sys
import numpy as np
import math
import collections
from collections import deque 
from functools import reduce


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

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

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

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

ans = 0
b_cnt = m
for a_cnt in range(n+1):
    if a_li[a_cnt] > k:
        continue
    while a_li[a_cnt] + b_li[b_cnt] > k:
        b_cnt -= 1
    ans = max(ans,a_cnt+b_cnt)
print(ans)

Solution (Python):
N, M, K = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
a = [0] * (N+1)
b = [0] * (M+1)
for i in range(N):
    a[i+1] = a[i] + A[i]
for i in range(M):
    b[i+1] = 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)

Solution (Python):
from bisect import bisect
N, M, K = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
a = [0] * (N+1)
b = [0] * (M+1)
for i in range(N):
    a[i+1] = a[i] + A[i]
for i in range(M):
    b[i+1] = b[i] + B[i]
ans = 0
for i in range(N+1):
    tmp = K - a[i]
    if tmp < 0:
        break
    ans = max(ans, i + bisect(b, tmp) - 1)
print(ans)

Solution (Python):
n, m, k = map(int, input().split())
a_i = [int(x) for x in input().split()]
b_i = [int(x) for x in input().split()]

csum_a = [0]
csum_b = [0]

for i in range(n):
    csum_a.append(csum_a[i] + a_i[i])
    
for i in range(m):
    csum_b.append(csum_b[i] + b_i[i])
    
b_num = m + 1
ans = 0

for i in range(n + 1):
    for j in reversed(range(b_num)):
        if csum_a[i] + csum_b[j] <= k:
            ans = max(ans, i + j)
            b_num = j + 1
            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 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] + a[i] > 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()))

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

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

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

    while cum_b[val] > k - cum_a[i]:
        val -= 1

    ans = max(ans, i + val)

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.insert(0, 0)
b.insert(0, 0)
ans = 0
num_a = n
num_b = 0
flg = True

total_time = sum(a)
if total_time <= k:
    ans = n

for i in range(n+1):
    for j in range(num_b, m):
        if total_time + b[num_b+1] > k:
            break
        else:
            total_time += b[num_b+1]
            num_b += 1
        if num_a + num_b > ans:
            ans = num_a + num_b
    total_time -= a[num_a]
    num_a -= 1

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()))
cumA, cumB = [0], [0]

for i in range(len(A)):
    cumA.append(cumA[-1]+A[i])
for i in range(len(B)):
    cumB.append(cumB[-1]+B[i])

ans = 0
for i in range(n+1):
    tmp = cumA[i]
    if tmp > k:
        break
    else:
        rest = k-tmp
        ans = max(ans, i+bisect_right(cumB, rest)-1)
print(ans)

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

N,M,K = map(int,readline().split())
A = [0] + list(map(int,readline().split()))
B = [0] + list(map(int,readline().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]
  
ans = 0
b_ind = len(B) - 1
for i in range(len(A)):
  if A[i] > K:
    continue
  while b_ind >= 1 and A[i] + B[b_ind] > K:
    b_ind -= 1
    
  if i + b_ind > ans:
    ans = i + b_ind
    
print(ans)

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

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

Solution (Python):


def get_input() -> tuple:
    """
    標準入力を取得する.

    Returns:\n
        tuple: 標準入力
    """
    N, M, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    return N, M, K, A, B


def main(N: int, M: int, K: int, A: list, B: list) -> None:
    """
    メイン処理.

    Args:\n
        N (int): 机Aの本の数（1 <= N <= 200000）
        M (int): 机Bの本の数（1 <= M <= 200000）
        K (int): 合計所要時間の上限（1 <= K <= 10^9）
        A (list): 机Aの本を読むための時間
        B (list): 机Bの本を読むための時間
    """
    
    a, b = [0], [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)


if __name__ == "__main__":
    
    N, M, K, A, B = get_input()

    
    main(N, M, K, A, B)