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):
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))


A_min = [0]
for i in range(N):
  A_min.append(A_min[i]+A[i])
B_min = [0]
for i in range(M):
  B_min.append(B_min[i]+B[i])


ans = 0
B_len = M
for i in range(len(A_min)):
  if A_min[i] > K:
    break
  while B_min[B_len] > K - A_min[i]:
    B_len -= 1
  ans = max(ans,i+B_len)
print(ans)

Solution (Python):
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n,m,k = inpm()
a = [0] + inpl()
b = [0] + inpl()
aa = [0]
bb = [0]
for i in range(1,len(a)):
  aa.append(a[i] + aa[i-1])
for i in range(1,len(b)):
  bb.append(b[i] + bb[i-1])

ans = 0
for i in range(n+1):
    zan = k - aa[i]
    if zan < 0:
        break
    bcnt = bisect.bisect(bb,zan)
    ans = max(ans,i+bcnt-1)

print(ans)

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

N, M, K = map(int, input().split())
A_temp = [int(i) for i in input().split()]
B_temp = [int(i) for i in input().split()]

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

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

Solution (Python):
N, M, K = map(int, input().split())
A_temp = [int(i) for i in input().split()]
B_temp = [int(i) for i in input().split()]

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

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

Solution (Python):
import itertools

numOfA,numOfB,target = map(int, input().split())

timetoreadA = list(map(int,input().split()))
timetoreadB = list(map(int,input().split()))

timetoreadAacc = list(itertools.accumulate(timetoreadA))

booknumonlyA = 0
totaltime = 0
for time in timetoreadAacc:
	if target < time:
		break
	booknumonlyA += 1
	totaltime = time

bookreadA = booknumonlyA
bookread = [bookreadA]

for posB in range(numOfB):
	bookreadB = posB + 1
	newtime = totaltime + timetoreadB[posB]
	if newtime <= target:
		bookread.append(bookreadA + bookreadB)
		totaltime = newtime
	else:
		while newtime > target and bookreadA > 0:
			bookreadA -= 1
			newtime = newtime - timetoreadA[bookreadA]

		if newtime <= target:
			bookread.append(bookreadA + bookreadB)

		totaltime = newtime

print(max(bookread))

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

i = 0
ans = 0
j = m
while(i < len(a)):
    if a[i] > k:
        break

    else:
        while(b[j] > k-a[i]):
            j = j-1

        ans = max(ans,i+j)

    i = i+1

print(ans)

Solution (Python):
import sys
from bisect import bisect_left, bisect_right
N,M,K=map(int, sys.stdin.readline().split())
A=map(int, sys.stdin.readline().split())
B=map(int, sys.stdin.readline().split())

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

ans=0
for i in range(N+1):
    nokori=K-RUISEKI_A[i]
    if 0<=nokori:
        ans=max(ans,i+bisect_right(RUISEKI_B,nokori)-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]
  
import bisect

ans = 0
for i in range(len(A)):
  rest = K - A[i]
  if rest < 0:
    continue
  if ans < i:
    ans = i
  b_read = bisect.bisect_right(B, rest)
  if ans < i + b_read - 1:
    ans = i + b_read - 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]
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 n in range(N + 1):
  if A[n] > K:
    break
  while B[j] > K - A[n]:
      j -= 1
  ans = max(ans, n + j)
print(ans)

Solution (Python):
N, M, K = map(int, input().split())
A_temp = [int(i) for i in input().split()]
B_temp = [int(i) for i in input().split()]

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

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

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

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

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

SumA = [0]
SumB = [0]
cnt = 0
for i in range(N):
    SumA.append(SumA[i] + A[i])
for i in range(M):
    SumB.append(SumB[i] + B[i])

for i in range(N+1):
    if SumA[i] > K:
        break
    tmpcnt = bisect.bisect_right(SumB, K - SumA[i]) - 1
    
    
    
    
    
    cnt = max(cnt, i + tmpcnt)
print(cnt)

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

Solution (Python):
n, m, k = map(int, input().split(' '))
a_books = [0] + list(map(int, input().split(' ')))
b_books = [0] + list(map(int, input().split(' ')))
result = 0

for i in range(1, n+1):
    a_books[i] += a_books[i-1]
for j in range(1, m+1):
    b_books[j] += b_books[j-1]

b_cnt = m
for a_cnt in range(n+1):
    if a_books[a_cnt] > k:
        break
    while a_books[a_cnt] + b_books[b_cnt] > k:
        b_cnt -= 1
    result = max(result, a_cnt + b_cnt)
print(result)

Solution (Python):
import itertools

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

acc_A = [0]+list(itertools.accumulate(A))
acc_B = [0]+list(itertools.accumulate(B))
    
ans, j = 0, m
for i in range(n+1):
    if acc_A[i] > k:
        break
    while acc_A[i] + acc_B[j] > k:
        j -= 1
    ans = max(ans, i+j)
print(ans)

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

a,b = [0], [0]

for i in range(n):
    a.append(a[i]+A[i])
for 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 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 = list(map(int, input().split()))
B_list = list(map(int, input().split()))

a = [0]
b = [0]


for i in range(N):
    a.append(a[i] + A_list[i])

for i in range(M):
    b.append(b[i] + B_list[i])

ans, j = 0, 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()))
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 = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]


def cusum(array):
    for i in range(len(array) - 1):
        array[i + 1] += array[i]


cusum(A)
cusum(B)
A = [0] + A
B = [0] + B
tsundoku = 0
ia = 0
ib = M

for ia in range(N + 1):
    if A[ia] > K:
        break
    while A[ia] + B[ib] > K and ib >= 0:
        ib -= 1
    tsundoku = max(ia + ib, tsundoku)

print(tsundoku)

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

sa = [0]
for i, val in enumerate(A):
  sa.append(sa[i] + val)

sb = [0]
for i, val in enumerate(B):
  sb.append(sb[i] + val)

max_num = 0
ind_max = M
for i in range(N+1):
  if(sa[i]>K):
    break
  c = 0
  for k in range(ind_max+1):
    if(sb[ind_max-k]<=K-sa[i]):
      break
    c += 1
  ind_max -= c
  max_num = max(max_num,i+ind_max)

      
      
print(max_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):
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do(): 
    n,m,k=INTM()
    A=LIST()
    B=LIST()
    As=[0]*(n+1)
    Bs=[0]*(m+1)
    ans=0
    for i in range(n):
        As[i+1]=As[i]+A[i]
    A=As
    for i in range(m):
        Bs[i+1]=Bs[i]+B[i]
    B=Bs
    

    if A[-1]+B[-1]<=k:
        ans=n+m

    b_s=m

    for i in range(n+1):

        if A[i]>k:
            
            temp=i-1
            ans=max(ans,temp)
            break
        for i2 in range(b_s,-1,-1):
            
            
            if A[i]+B[i2]<=k:
                temp=i+i2
                b_s=i2
                
                ans=max(ans,temp)
                break
        

    
    print(ans)

if __name__ == '__main__':
    do()

Solution (Python):
n,m,k = map(int,input().split())
nlist = list(map(int,input().split()))
mlist = list(map(int,input().split()))
result = 0


mrest = k


mcount = m


mtime = sum(mlist)


ntime = 0


for ncount in range(len(nlist) + 1):
  
  if ncount > 0:
    mrest -= nlist[ncount - 1]
    ntime += nlist[ncount - 1]
  
  if ntime > k:
    break;
  
  
  while mcount > 0 and mtime > mrest:
    mcount -= 1
    mtime -= mlist[mcount]
  
  result = max(result, ncount + mcount)
  
  if ncount == n:
    break;
print(result)

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

a, b = [0], [0]
max_sum = 0

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

for j in range(len(B)):
    b.append(b[j] + B[j])

j = len(B)
for i in range(len(A)+1):
    if a[i] > K:
        continue
    else:
        while b[j] > K - a[i]:
            j -= 1
        max_sum = max(max_sum, i + j)

print(max_sum)

Solution (Python):
s = list(map(int,input().split()))
N = s[0]
M = s[1]
K = s[2]

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

asum = [0]
bsum = [0]
apsum = 0
bpsum = 0
for times in a:
  apsum += times
  asum.append(apsum)
for times in b:
  bpsum += times
  bsum.append(bpsum)

nums = []
i = 0
j = M
for i in range(N+1):
  if asum[i]>K:
    pass
  else:
    while asum[i]+bsum[j] > K:
      j += -1
    nums.append(i+j)
print(max(nums))

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

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

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

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

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

Solution (Python):
n,m,k=map(int,input().split())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
ans=chk=0
w=-1
for i in range(n):
    if k>=a[i]:
        chk+=1
        k-=a[i]
        w=i
        ans=max(ans,chk)
    else:
        break

for i in range(m):
    if k<b[i]:
        while w>=0:
            if k>=b[i]: break
            k+=a[w]
            chk-=1
            w-=1
    if k>=b[i]:
        chk+=1
        k-=b[i]
        ans=max(ans,chk)
    else:
        break
print(ans)

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

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

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


import bisect
ans = 0
for i in range(N+1):
    if A[i] <= K:
        rest = K - A[i]
        b_cnt = bisect.bisect_right(B,rest)-1
        ans = max(ans,i+b_cnt)
    else:
        break
print(ans)

Solution (Python):
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
A_num = len(A)
B_num = len(B)
Ali = [0]
Bli = [0]
sumA = 0
sumB = 0
for a in range(A_num):
  sumA += A[a]
  Ali.append(sumA)
for b in range(B_num):
  sumB += B[b]
  Bli.append(sumB)
b_start = 0
time = 0
ans = 0
Bli.reverse()
for i in range(A_num+1):
  for j in range(b_start,B_num+1):
    time = Ali[i] + Bli[j]
    if time <= K:
      
      b_start = j
      ans = max(ans,i+(B_num - j))
      break
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()))

if a[0] > k:
    res = 0
    for i in range(m):
        if b[i] <= k:
            k -= b[i]
            res += 1
        else:
            break
    print(res)
else:
    cnt = 0
    a_idx = 0
    for i in range(n):
        if a[i] <= k:
            k -= a[i]
            cnt += 1
            a_idx = i
        else:
            break
    
    b_idx = -1
    for i in range(m):
        if b[i] <= k:
            k -= b[i]
            cnt += 1
            b_idx = i
        else:
            break
    
    res = cnt

    for i in range(a_idx,-1,-1):
        k += a[i]
        cnt -= 1
        fi = b_idx
        for j in range(b_idx+1,m):
            if b[j] <= k:
                k -= b[j]
                cnt += 1
                fi = j
            else:
                break
        b_idx = fi
        res = max(res,cnt)
    print(res)

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

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

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

Solution (Python):
if __name__ == "__main__":
    N, M, K = map(int, input().split())
    A = [int(i) for i in input().split()]
    B = [int(i) for i 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(len(a)):
        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 = [int(i) for i in input().split()]
B = [int(i) for i 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(len(a)):
    if a[i] > K:
        break
    while a[i] + b[j] > K:
        j -= 1
    ans = max(ans, i + j)

print(ans)

Solution (Python):
def main():
    N, M, K = map(int, input().split())
    A = [int(i) for i in input().split()]
    B = [int(i) for i 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(len(a)):
        if a[i] > K:
            break
        while a[i] + b[j] > K:
            j -= 1
        ans = max(ans, i + j)

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import sys


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


def main():
    N, M, K = map(int, input().split())
    A = [int(i) for i in input().split()]
    B = [int(i) for i 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(len(a)):
        if a[i] > K:
            break
        while a[i] + b[j] > K:
            j -= 1
        ans = max(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 = [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):
n,m,k = map(int, input().split())

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

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

b_cnt=m
ans=0

for a_cnt in range(n+1):
    if a[a_cnt]>k:
        break
    while a[a_cnt]+b[b_cnt]>k:
         b_cnt-=1
    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()))

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

s2 = [0]
for i in range(m):
    s2.append(s2[-1]+b[i])
ans = 0
j = m
for i in range(n+1):
    
    if k-s1[i]<0:
        break
    while k-s1[i]-s2[j]<0 and j>0:
            j -= 1 
    ans = max(i+j,ans)
print(ans)

Solution (Python):

import sys


def solve(N: int, M: int, K: int, A: "List[int]", B: "List[int]"):
    a = 0
    a_n = [a]
    for a_i in A:
        a += a_i
        a_n.append(a)

    b = 0
    b_n = [b]
    for b_i in B:
        b += b_i
        b_n.append(b)

    ans = 0
    j = M
    for i, a in enumerate(a_n):
        if a > K:
            break
        while b_n[j] > (K-a):
            j -= 1
        ans = max(ans, i+j)

    return ans



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    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)]  
    print(solve(N, M, K, A, B))

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):
from itertools import accumulate
from bisect import bisect_right
N, M, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = list(map(int, input().split()))
SA = list(accumulate(A))
SB = list(accumulate(B))

ans = 0
for n in range(len(SA)):
    tmp = K-SA[n]
    if tmp < 0:
        break
    m = bisect_right(SB, tmp)
    ans = max(ans, n+m)
print(ans)

Solution (Python):
from itertools import accumulate

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

a_acc = [0] + list(accumulate(a))  
b_acc = [0] + list(accumulate(b))  

ans = 0
for an in range(n + 1):
    rem = k - a_acc[an]
    if rem < 0:
        break

    
    ok = 0
    ng = m + 1   
    
    while abs(ng - ok) > 1:
        mid = (ok + ng) // 2
        
        if b_acc[mid] <= rem:
        
            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 = list(map(int, input().split()))
b_list = list(map(int, input().split()))

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

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

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

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

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

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

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

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

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

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7





def or_less(array, x):
    
    
    index = bisect_right(array, x)
    if index == 0:
        or_less_int = -float('inf')
    else:
        or_less_int = array[index - 1]
    return [index, or_less_int]

N, M, K = getNM()
A = getList()
A.insert(0, 0)
B = getList()

A_imos = copy.deepcopy(A)
for i in range(N):
    A_imos[i + 1] += A_imos[i]

B_imos = copy.deepcopy(B)
for i in range(M - 1):
    B_imos[i + 1] += B_imos[i]

ans = 0
for i in range(N + 1):
    if A_imos[i] > K:
        continue
    index = or_less(B_imos, K - A_imos[i])[0]
    ans = max(ans, i + index)
print(ans)

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7





def or_less(array, x):
    
    
    index = bisect_right(array, x)
    if index == 0:
        or_less_int = -float('inf')
    else:
        or_less_int = array[index - 1]
    return [index, or_less_int]

N, M, K = getNM()
A = getList()
B = getList()

A_imos = copy.deepcopy(A)
for i in range(N - 1):
    A_imos[i + 1] += A_imos[i]

B_imos = copy.deepcopy(B)
for i in range(M - 1):
    B_imos[i + 1] += B_imos[i]

ans = 0

for i in range(M):
    if B_imos[i] <= K:
        ans = (i + 1)

for i in range(N):
    if A_imos[i] > K:
        continue
    index = or_less(B_imos, K - A_imos[i])[0]
    ans = max(ans, (i + 1) + index)
print(ans)

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

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

ans = 0
tmp = m
for i in range(n+1):
    for j in range(tmp+1)[::-1]:
        if s_a[i] + s_b[j] <= k:
            ans = max(ans, i+j)
            tmp = j
            break
print(ans)

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

sum_a = [0]
sum_b = [0]

for i in range(N):
    sum_a.append(sum_a[-1] + desk_a[i])
for i in range(M):
    sum_b.append(sum_b[-1] + desk_b[i])

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

print(ans)

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

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

    ans = 0
    j = M
    for i in range(N+1):
        if Asum[i] > K:
            break
        while Bsum[j] > K - Asum[i]:
            j-=1         
        ans = max(ans,i+j)
    print(ans)
resolve()

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

i = 0
j = 0
count = 0
a = [0]*N
b = [0]*M
ans = 0

sum = 0
for i in range(N):
    sum += A[i]
    a[i] = sum
sum = 0
for j in range(M):
    sum += B[j]
    b[j] = sum

ind = bisect.bisect_right(b, K)
ans = ind

for i in range(N):
    if a[i] <= K:
        ind = bisect.bisect_right(b, K-a[i])
        ans = max(ans, ind+i+1)
    else:
        break

print(ans)