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):
if __name__ == "__main__":
    n,m,k = (int(x) for x in input().split())
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]

    pre = 0
    for i in range(len(a)):
        pre += a[i]
        a[i] = pre
    
    pre = 0
    for i in range(len(b)):
        pre += b[i]
        b[i] = pre

    ans = 0
    for i in range(-1,len(a)):
        have = k
        if i >= 0:
            have -= a[i]
        if have <0:
            continue
        ans = max(ans, i+1)
        if b[0] > have:
            continue
        low, high = (0, len(b)-1)
        while low<=high:
            mid = (low+high)//2
            if have >= b[mid]:
                low = mid + 1
            else:
                high = mid - 1
        ans = max(ans, i+1 + high+1)
    print(ans)

Solution (Python):
import math

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

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

print(ans)

Solution (Python):
"""
    Satwik_Tiwari ;) .
    4th july , 2020  - Saturday
"""



from __future__ import division, print_function

from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase


import bisect
from heapq import *
from math import *
from collections import deque
from collections import Counter as counter  
from itertools import combinations as comb 
from itertools import permutations as permutate
from bisect import bisect_left as bl


from bisect import bisect_right as br
from bisect import bisect





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


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)






mod = 1000000007
def inp(): return sys.stdin.readline().rstrip("\r\n") 
def out(var): sys.stdout.write(str(var))  
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())

def zerolist(n): return [0]*n
def nextline(): out("\n")  
def testcase(t):
    for p in range(t):
        solve()
def printlist(a) :
    for p in range(0,len(a)):
        out(str(a[p]) + ' ')
def lcm(a,b): return (a*b)//gcd(a,b)
def power(a,b):
    ans = 1
    while(b>0):
        if(b%2==1):
            ans*=a
        a*=a
        b//=2
    return ans
def ncr(n,r): return factorial(n)//(factorial(r)*factorial(max(n-r,1)))
def isPrime(n) : 
    if (n <= 1) : return False
    if (n <= 3) : return True
    if (n % 2 == 0 or n % 3 == 0) : return False
    i = 5
    while(i * i <= n) :
        if (n % i == 0 or n % (i + 2) == 0) :
            return False
        i = i + 6
    return True



def bs(a,l,h,x):
    while(l<h):
        
        mid = (l+h)//2
        if(a[mid] == x):
            return mid
        if(a[mid] < x):
            l = mid+1
        else:
            h = mid
    return l

def sieve(a): 
    
    for i in range(3,((10**6)+1),2):
        a[i] = 1
    
    for i in range(3,((10**6)+1),2):
        for j in range(i*i,((10**6)+1),i):
            a[j] = 0
    a[2] = 1 
    return (a)


def bfs(g,st):
    visited = [-1]*(len(g))
    visited[st] = 0
    queue = []
    queue.append(st)
    new = []
    while(len(queue) != 0):
        s = queue.pop()
        new.append(s)
        for i in g[s]:
            if(visited[i] == -1):
                visited[i] = visited[s]+1
                queue.append(i)
    return visited


def dfsusingstack(v,st):
    d = deque([])
    visited = [0]*(len(v))
    d.append(st)
    new = []
    visited[st] = 1
    while(len(d) != 0):
        curr = d.pop()
        new.append(curr)
        for i in v[curr]:
            if(visited[i] == 0):
                visited[i] = 1
                d.append(i)
    return new



def solve():
    n,m,k = sep()
    a = lis()
    b = lis()

    prea = []
    preb = []
    for i in range(n):
        if(i==0):
            prea.append(a[i])
            continue
        prea.append(a[i] + prea[i-1])
    for i in range(m):
        if(i==0):
            preb.append(b[i])
            continue
        preb.append(b[i] + preb[i-1])
    
    
    ans  = 0
    for i in range(0,n):
        if(prea[i]<=k):
            ind = bl(preb,k-prea[i])
            if(ind<m and preb[ind] == k-prea[i]):
                ans = max(ans,i+ind+2)
            else:
                ans = max(ans,i+ind+1)
            
    for i in range(m):
        if(preb[i] <=k):
            ind = bl(prea,k-preb[i])
            if(ind<n and prea[ind] == k-preb[i]):
                ans = max(ans,i+ind+2)
            else:
                ans = max(ans,i+ind+1)
                
    print(ans)



testcase(1)

Solution (Python):
import sys 
import numpy as np
import bisect as bs 

def binarySearch_canread(data, target):
    if len(data) == 0:
        return None
    if len(data) == 1:
        return data[0]

    
    if target > max(data):
        return len(data)
    elif target < min(data):
        return 0

    min_diff = float('inf')
    imin = 0
    imax = len(data) - 1
    closest_num = None

    while imin <= imax:
        imid = imin + (imax - imin) // 2

        if imid + 1 < len(data):
            min_diff_right = abs(data[imid + 1] - target)
        if imid > 0:
            min_diff_left = abs(data[imid - 1] - target)

        if min_diff_left < min_diff:
            min_diff = min_diff_left 
            closest_num = data[imid - 1]
        if min_diff_right < min_diff:
            min_diff = min_diff_right
            closest_num = data[imid + 1]

        if data[imid] < target:
            imin = imid + 1
        elif data[imid] > target:
            imax = imid - 1
        else:
            return list(data).index(data[imid]) + 1 

    
    differ = target - closest_num
    can_read = None
    if differ > 0: 
        can_read = max([i for i, x in enumerate(data) if x == closest_num]) + 1
    elif differ < 0: 
        can_read = min([i for i, x in enumerate(data) if x == closest_num])



    return can_read

if __name__ == '__main__':
    read = sys.stdin.buffer.read 
    readline = sys.stdin.buffer.readline
    readlines = sys.stdin.buffer.readlines 

    N, M, K = map(int, readline().split())
    A = np.array(readline().split(), np.int64)
    B = np.array(readline().split(), np.int64)

    Acum = np.zeros(N+1, np.int64)
    Acum[1:] = np.cumsum(A)
    Bcum = np.zeros(M+1, np.int64)
    Bcum[1:] = np.cumsum(B)

    
    max_read = 0
    
    for i, cumNum in enumerate(Acum): 
        if cumNum <= K:
            limit = K - cumNum
            
            can_reading = i + bs.bisect_right(Bcum[1:], limit)
            if (max_read < can_reading):
                max_read = can_reading

    print(max_read)

Solution (Python):

import sys
from collections import deque


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


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


def main():
    n, m, k = MI()
    a = deque(LI())
    b = deque(LI())

    A, B = [0], [0]

    for i in range(len(a)):
        A.append(A[i]+a[i])
    for i in range(len(b)):
        B.append(B[i]+b[i])

    index = m
    ans = [0]
    for i in range(len(a)+1):
        rest = k - A[i]
        if rest < 0:
            break

        while B[index] > rest:
            index -= 1

        ans.append(i + index)

    print(max(ans))


    
    
main()

Solution (Python):

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

A_CumulativeSum = [0]
B_CumulativeSum = [0]
for i in range(n):
    A_CumulativeSum.append(A[i] + A_CumulativeSum[i])
for i in range(m):
    B_CumulativeSum.append(B[i] + B_CumulativeSum[i])

if A_CumulativeSum[n-1] + B_CumulativeSum[m-1] <= k:
    print(n+m)
    sys.exit()

ans = 0
j = m
for i in range(n+1):
    time = A_CumulativeSum[i]
    if time > k:
        break
    time_b = k - time
    while time_b < B_CumulativeSum[j]:
        j -= 1

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

print(ans)

Solution (Python):
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
an = 0
bn = 0
t = 0
for an in range(n):
  if t+a[an] <= k:
    t += a[an]
  else:
    an-=1
    break
an+=1
ans = an
while True:
  while bn < m:
    if t+b[bn] <= k:
      t += b[bn]
      bn += 1
    else:
      break
  ans = max(ans,an+bn)
  if an == 0 or bn == m:
    break
  else:
    an -= 1
    t -= a[an]
print(ans)

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

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

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

print(ans)

Solution (Python):













import numpy as np    







MOD = 10**9 + 7
N,M,K = map(int,input().split())

arrA = np.array([0] + list(map(int,input().split())))
arrB = np.array([0] + list(map(int,input().split())))

arrA = np.cumsum(arrA,dtype="int64")
arrB = np.cumsum(arrB,dtype="int64")


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

print(ans)

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

i_l, j_l = [0], [0]

best0 = M
ans = 0

for i in range(N):
    i_l.append(i_l[i] + a_l[i])

for i in range(M):
    j_l.append(j_l[i] + b_l[i])











for k in range(N+1):
    if i_l[k] > K:
        break
    while i_l[k] + j_l[best0] > K:
        best0 -= 1
    ans = max(ans, k+best0)
print(ans)

Solution (Python):
import numpy

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

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

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

acc_a = numpy.array(acc_a)
acc_b = numpy.array(acc_b)

currentMax = 0
bnum = M
for anum in range(N + 1):
    if acc_a[anum] > K:
        break

    while True:
        if acc_b[bnum] > K - acc_a[anum]:
            bnum = bnum - 1 
        else:
            break

    currentMax = max(currentMax, anum + bnum)


print(currentMax)

Solution (Python):
import bisect
n, m, k = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
SA, SB = [0], [0]
for i in range(n):
    SA.append(SA[i] + A[i])
for j in range(m):
    SB.append(SB[j] + B[j])
ans = 0
for i in range(n + 1):
    if SA[i] <= k:
        j = bisect.bisect_right(SB, k - SA[i]) - 1
        ans = max(ans, i + j)
print(ans)

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

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

sum_a = [0]
sum_b = [0]

for i in range(n):
    sum_a.append(sum_a[-1] + a[i])

for i in range(m):
    sum_b.append(sum_b[-1] + b[i])

ans = 0
j = m
for i in range(n + 1):
    while sum_a[i] + sum_b[j] > k and j >= 0:
        j -= 1

    if j < 0:
        break

    if sum_a[i] + sum_b[j] <= k:
        ans = max(ans, i + j)

print(ans)

Solution (Python):

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

a=[0]
b=[0]
for i in range(N):
    a.append(a[i]+A[i])
for j in range(M):
    b.append(b[j]+B[j])
ans = 0
l = M
for k in range(N+1):
    if a[k] > K:
        break
    while b[l] > K - a[k]:
        l -= 1
    ans = max(ans,k+l)
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])
res = 0
output = 0
j = M
num = 0
for i in range(N + 1):
  if K < a[i]:
    break
  else:
    res = K - a[i]
  while b[j] > res:
    j -= 1
  num = i + j 
  output = max(output, num)
print(output)

Solution (Python):
from itertools import accumulate
n,m,k=map(int,input().split())
A=list(accumulate(map(int,input().split()),initial=0))
B=list(accumulate(map(int,input().split()),initial=0))
r,j=0,m
for i in range(n+1):
  if A[i]>k:
    break
  while A[i]+B[j]>k:
    j-=1
  r=max(r,i+j)
print(r)

Solution (Python):

def calc_cusum(n):
	cusum = [0] * (n + 1)
	arr = input().split()
	
	for i in range(n):
		cusum[i + 1] = cusum[i] + int(arr[i])
	
	return cusum


def get_max_book(cusum):
  global k
  
  for i in range(len(cusum)):
    if cusum[i] > k:
      return i -1
  
  return len(cusum) - 1


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

ans = 0
j = get_max_book(b)

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

print(ans)

Solution (Python):

def calc_cusum(n):
	cusum = [0] * (n + 1)
	arr = input().split()
	
	for i in range(n):
		cusum[i + 1] = cusum[i] + int(arr[i])
	
	return cusum


def identify_position(i, j):
  global a
  global b
  global k
  global m
  
  if a[i] + b[j] > k:
    while j > 0:
      j -= 1
      
      if a[i] + b[j] <= k:
        break
  else:
    while j < m and a[i] + b[j+1]<= k:
      j += 1
  
  return j


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

ans = 0
j = 0

for i in range(n + 1):
  j = identify_position(i, j) 
  
  
  
  
  
  if a[i] + b[j] <= k:
    ans = max(ans, i+j)

print(ans)

Solution (Python):
import itertools

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


A_accum = [0] + list(itertools.accumulate(A))
B_accum = [0] + list(itertools.accumulate(B))

book_num = 0

b_best = M
for n in range(N + 1):
    for m in range(b_best, -1, -1):
        if A_accum[n] + B_accum[m] <= K:
            b_best = m
            if book_num < n + m:
                book_num = n + m
            break

print(book_num)

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

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

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

ruiA = [0]
ruiB = [0]
for i in range(N):
    ruiA.append(ruiA[-1] + A[i])
for i in range(M):
    ruiB.append(ruiB[-1] + B[i])

MAX = 0
j = M

for i in range(N+1):
    if ruiA[i] > K:
        break
    while ruiA[i] + ruiB[j] > K:
        j -= 1
    MAX = max(MAX, i+j)

print(MAX)

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

aa = list(accumulate(a))
aa.insert(0,0)
bb = list(accumulate(b))
bb.insert(0,0)

ans = 0

for i in range(n+1):
    if aa[i] > k:
        break
    nokori = k-aa[i]
    kazu = bisect.bisect_right(bb, nokori)
    ans = max(ans,i+kazu-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, b = [0], [0]
for i in range(N):
        a.append(a[i]+A[i])
for i in range(M):
        b.append(b[i]+B[i])

ans, j = 0, M

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

print(ans)

Solution (Python):
from collections import deque
import numpy as np
n,m,k = map(int,input().split())
A = deque(map(int,input().split()))
B = deque(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])

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

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

print(ans)

Solution (Python):
from bisect import bisect_right
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
CA = [0 for _ in range(N+1)]
for i in range(N):
    CA[i+1] = A[i]+CA[i]
CB = [0 for _ in range(M+1)]
for j in range(M):
    CB[j+1] = B[j]+CB[j]
cmax = 0
for i in range(N,-1,-1):
    if CA[i]<=K:
        b = K-CA[i]
        ind = bisect_right(CB,b)
        cmax = max(cmax,i+ind-1)
print(cmax)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

from itertools import accumulate
N, M, K = mapint()
As = [0]+list(accumulate(list(mapint())))
Bs = list(accumulate(list(mapint())))
from bisect import bisect_right

ans = 0
for i, a in enumerate(As):
    if a>K:
        break
    idx = bisect_right(Bs, K-a)
    ans = max(ans, i+idx)
print(ans)

Solution (Python):
import numpy as np
import bisect
n,m,k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = [0]+list(np.cumsum(A))
b = [0]+list(np.cumsum(B))
ans = 0
for i in range(len(a)):
    x = k-a[i]
    if x < 0: break
    I = bisect.bisect_left(b, x)
    if I >= len(b): I -= 1
    if b[I] > x:
        if I != 0: I -= 1
        else: continue
    ans = max(ans, i+I)
print(ans)

Solution (Python):
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
from bisect import bisect_right
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]

ans=0
for i in range(n+1):
  t=k-sa[i]
  if t<0:continue
  idx=bisect_right(sb,t)
  ans=max(ans,idx+i-1)
print(ans)

Solution (Python):
from collections import deque
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
SA = [0]
for i in range(N):
  temp = SA[-1] + A[i]
  SA.append(temp)
 
SB = [0]
for j in range(M):
  temp = SB[-1] + B[j]
  SB.append(temp)
ans = 0
for i in range(N+1):
  an = i
  if SA[i] > K:
    break
  else:
    nokori = K -SA[i]
    if nokori >= SB[-1]:
      bn = M
    else:
      ok = 0
      ng = M
      while abs(ok-ng) > 1:
        mid = (ok+ng)//2
        if nokori >= SB[mid]:
          ok = mid
        else:
          ng = mid
      bn = ok
  
  ans = max(ans,an+bn)
print(ans)

Solution (Python):
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
asum=[0]
bsum=[0]
current=0
for i in range(n):
  current+=a[i]
  asum.append(current)
current=0
for i in range(m):
  current+=b[i]
  bsum.append(current)
pointer=0
for i in range(n+1):
  if asum[i]>k:
    pointer=i-1
    break
  if i==n:
    pointer=n
ans=pointer
bpointer=0
for i in range(pointer,-1,-1):
  while bpointer<m and bsum[bpointer+1]+asum[i]<=k:
    bpointer+=1
  ans=max(ans,i+bpointer)
print(ans)

Solution (Python):
from itertools import accumulate
import bisect

n, m, k = map(int, input().split())
A = [0] + list(accumulate(map(int, input().split())))
B = [0] + list(accumulate(map(int, input().split())))
ans = 0
for i, a in enumerate(A):
  if a > k:
    break
  temp = i + bisect.bisect_right(B, k-a)-1
  ans = max(ans, temp)
print(ans)

Solution (Python):
from bisect import *
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=[0]
for i in range(N):
  C.append(C[i]+A[i])
D=[0]
for i in range(M):
  D.append(D[i]+B[i])
P=0
for i in range(N+1):
  if C[i]>K:
    break
  P=max(P,i+bisect_right(D,K-C[i])-1)
print(P)

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):
"https://codeforces.com/contest/1328/problem/A"
import collections, heapq, itertools, math, functools
groupby = itertools.groupby
rs  = lambda: input()
ri  = lambda: int(input())
rm  = lambda: map(int, input().split())
rai = lambda: [int(x) for x in input().split()]

from functools import reduce

def solve():
    N, M, K = rm()
    A = rai()
    B = rai()
    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)
    return ans
print(solve())

Solution (Python):
import bisect

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

res = 0
a_ = 0
for i in range(n+1):
    if a[i] > k:
        break
    j = bisect.bisect(b, k-a[i]) - 1
    res = max(res, i+j)

print(res)

Solution (Python):
import bisect

n, m, k = map(int, input().split())
a = [0] + [int(x) for x in input().split()]
b = [0]
for x in input().split():
    b.append(b[-1] + int(x))

res = 0
a_ = 0
for i in range(n+1):
    a_ += a[i]
    if a_ > k:
        break
    b_max = k - a_
    b_num = bisect.bisect(b, b_max) - 1
    res = max(res, i + b_num)

print(res)

Solution (Python):

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

N = a[0]
M = a[1]
K = a[2]

count = 0 
count_time = 0 
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):
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] > k - A[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)

Solution (Python):
import numpy as np
import bisect

def solve(n, m, k, a, b):
    s = np.cumsum([0]+a)
    t = np.cumsum(b)
    best = 0
    for i in range(n+1):
        if s[i] > k:
            break
        j = bisect.bisect_right(t, k - s[i])
        best = max(best, i+j)
    return best

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

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

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

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

accA = list(accumulate(A, initial=0))
accB = list(accumulate(B, initial=0))

ans = 0
for c, a in enumerate(accA):
    if K - a < 0:
        continue
    ans = max(ans, c + bisect_right(accB, K - a) - 1)
print(ans)

Solution (Python):
import numpy as np
n, m, k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
cum_a = np.r_[0,np.cumsum(a)]


cum_b = np.cumsum(b)



ans = 0
for i in range(n + 1):
    
    
    
    
    
    
    
    
    
    
    if cum_a[i] > k:
    
    
        
        i = 0
    
    s = np.searchsorted(cum_b, k - cum_a[i], side = "right")

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

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

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

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


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

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


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

print(ans)

Solution (Python):
import sys
from itertools import accumulate
import bisect
n, m, k = [int(i) for i in sys.stdin.readline().split()]
a_ls = [int(i) for i in sys.stdin.readline().split()]
b_ls = [int(i) for i in sys.stdin.readline().split()]
a_ls = [i for i in accumulate([0] + a_ls)]
b_ls = [i for i in accumulate([0] + b_ls)]
i = 0
best = 0
while i <= n and a_ls[i] <= k:
    res = i + bisect.bisect_right(b_ls, k - a_ls[i]) - 1
    best = max(best, res)
    i += 1
print(best)

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

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

ans,j=0,M

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

print(ans)

Solution (Python):
from 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_cumu = [0] + list(accumulate(A))
B_cumu = [0] + list(accumulate(B))

curr_max = 0
for i in range(N + 1):
    curr = A_cumu[i]
    if curr > K:
        break
    j = bisect_right(B_cumu, K - curr) - 1
    curr_max = max(curr_max, i + j)

print(curr_max)

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

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

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

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

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 math
import sys
import itertools
from math import gcd
from math import sqrt
from sys import stdin
def input() : return stdin.readline().rstrip()
def mips():
    return map(int,input().split())
def ii():
    return int(input())
sys.setrecursionlimit(10**9)

N,M,K = mips()
A = [i for i in mips()]
B = [i for i in mips()]

ans = 0
clock = K
A2 = [0]
B2 = [0]
for i in range(1,N+1):
    ai = A2[i-1] + A[i-1]
    A2.append(ai)
for i in range(1,M+1):
    bi = B2[i-1] + B[i-1]
    B2.append(bi)
j = M
for i in range(N+1):
    if A2[i] > K:
        break
    while (B2[j] + A2[i] > K):
        j -= 1
    ans = max(ans,i+j)
print(ans)