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 = [0]*(n+1)

for i in range(n):
    A[i+1] = A[i] +a[i]

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

A = list(map(int, input().split()))
B = list(map(int, input().split()))
a_sum = []
b_sum = []
sm = 0
for a in A:
    sm += a
    if sm > K:
        break
    a_sum.append(sm)
sm = 0
for b in B:
    sm += b
    if sm > K:
        break
    b_sum.append(sm)
index_max = 0


while a_sum:
    a_size = len(a_sum)
    b_index = bisect.bisect_right(b_sum, K - a_sum.pop())
    index_max = max(index_max, a_size + b_index)
    
b_index = bisect.bisect_right(b_sum, K)
index_max = max(index_max, b_index)
print(index_max)

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

b2=[]
b2.append(0)
for i in range(1,m+1):
  b2.append(b2[i-1]+b[i-1])
a.insert(0,0)
cnt=0
a_sum=0
for i in range(n+1):
  j=m
  a_sum+=a[i]
  while True:
    if k>=a_sum+b2[j]:
      cnt=max(cnt,i+j)
      m=j
      break
    j-=1
    if j <0:
      break
print(cnt)

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

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

A.append(math.inf)
B.append(math.inf)

best = 0
i = j = 0

while K >= A[i]:
    K -= A[i]
    i += 1

while True:
    while K >= B[j]:
        K -= B[j]
        j += 1

    best = max(best, i+j)

    if i == 0: break

    i -= 1
    K += A[i]

print(best)

Solution (Python):
import bisect

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

As = list(map(int, input().split()))
Bs = list(map(int, input().split()))

sAs = [0]
sBs = [0]
for a in As:
  sAs.append(sAs[-1]+a)
for b in Bs:
  sBs.append(sBs[-1]+b)
  
rlt = 0
for i in range(N+1):
  t = K - sAs[i]
  if t < 0:
    break
  j = bisect.bisect_right(sBs, t)
  rlt = max(rlt, i+j-1)
  
print(rlt)

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

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

ans = 0
j = m
for i in range(n + 1):
    if a_sums[i] > k:
        break
    while a_sums[i] + b_sums[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(' ')))
sa = [0] * (n+1)
sb = [0] * (m+1)

for i in range(n):
  sa[i+1] = a_list[i] + sa[i]
for j in range(m):
  sb[j+1] = b_list[j] + sb[j]

best=0
r = m
for i, a in enumerate(sa):
  if a>k:
    break
  while ((a + sb[r]) > k) & (r>=0):
    r-=1
    
  best = max(best,i+r)
      
  
    
print(best)

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

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

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

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

ans = 0

a, b = [0], [0]

j = m

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

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

acum2 = [0]
for i in range(m):
    acum2.append(acum2[-1] + arr2[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=list(map(int, input().split()))
B=list(map(int, input().split()))
ans=0
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])
j=m
for i in range(n+1):
    if k<a[i]:
        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()))
A_sum = sum(A)
B_sum = 0
n, m = N, 0
ans= 0
while m != M:
  if A_sum + B_sum <= K:
    ans = max(ans, n+m)
    m += 1
    B_sum += B[m]
  elif A_sum + B_sum > K and n >= 0:
    A_sum -= A[n]
    n -= 1
  else:
    break
if A_sum + B_sum <= K:
  ans = max(ans, n+m)    
print(ans)

Solution (Python):
def solve():
    n,m,k = list(map(int,input().split()))
    arr = list(map(int, input().split()))
    arr1 = list(map(int, input().split()))
    aTrack = 0
    bTrack = sum(arr1)
    Bn = len(arr1)
    ans = 0
    for An in range(len(arr)+1):
      if An>0:
        aTrack += arr[An-1]
      if aTrack>k:
        break
      while aTrack+bTrack>k:
        Bn -= 1
        bTrack -= arr1[Bn]
      ans = max(ans, An+Bn)
    print(ans)
    
            
solve()

Solution (Python):

if __name__=="__main__":
    N,M,K = map(int,input().split())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    A_sum_arr,B_sum_arr = [0],[0]
    for i in range(len(A)):
        A_sum_arr.append(A[i]+A_sum_arr[i])
    for i in range(len(B)):
        B_sum_arr.append(B[i]+B_sum_arr[i])
    count = 0
    j = len(B_sum_arr) - 1
    for i,A_sum in enumerate(A_sum_arr):
        if A_sum > K:
            break
        else:
            b_val = K - A_sum
            while b_val < B_sum_arr[j]:
                j -= 1
            count = max(count,(i+j))
    print(count)

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

acum1 = [0]
for _ in range(n):
    acum1.append(acum1[-1] + arr1[_])

acum2 = [0]
for _ in range(m):
    acum2.append(acum2[-1] + arr2[_])

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=list(map(int,input().split()))
B=list(map(int,input().split()))
c=0
b=0
for i in range(M):
    b+=B[i]
    if b<=K:
        c+=1
    else:
        break
a=0
b=sum(B)
j=M
ans=0
for i in range(N):
    a+=A[i]
    if a>K:
        break
    while a+b>K:
        b-=B[-1]
        B.pop(-1)
        j-=1
    ans=max(ans,i+j+1)
ans=max(ans,c)
print(ans)

Solution (Python):
n, m, k = map(int, input().split())
a_books = [int(i) for i in input().split()]
b_books = [int(i) for i in input().split()]

time = 0
count = 0
for i in range(n):
  time += a_books[i]
  if time > k:
    time -= a_books[i]
    i -= 1
    break
  count += 1
for j in range(m):
  time += b_books[j]
  if time > k:
    time -= b_books[j]
    j -= 1
    break
  count += 1
max_count = count

while j < m and i >= 0:
  time -= a_books[i]
  i -= 1
  count -= 1
  j += 1
  while j < m:
    time += b_books[j]
    if time > k:
      time -= b_books[j]
      j -= 1
      break
    count += 1
    j += 1
  if count > max_count:
    max_count = count
  
  
print(max_count)

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

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

acum2 = [0]
for i in range(m):
    acum2.append(acum2[-1]+arr2[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 = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]

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

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

ans, j = 0, M

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

Solution (Python):
import sys
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()))

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]

isb=m
ans = 0
for isa in range(n+1):
    if sa[isa]>k:
        break
    
    while sa[isa]+sb[isb]>k:
        isb-=1
    ans = max(ans, isa+isb)
    
print(ans)

Solution (Python):

def inputlist(): return [int(j) for j in input().split()]

N,M,K = inputlist()
A = inputlist()
B = inputlist()
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,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 bisect import bisect_right
from numpy import cumsum
from sys import stdin
input=stdin.readline
n,m,k=map(int,input().split())
a=[0]+list(map(int,input().split()))
b=list(map(int,input().split()))
a=cumsum(a)
b=cumsum(b)
ans=0
for i in range(len(a)):
  x=k-a[i]
  if x>=0:
    y=bisect_right(b,x)
    if ans<y+i:
      ans=y+i
  else:
    break
print(ans)

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

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

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


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

Solution (Python):
import math
def facts(n):
    ans = []
    for  i in range(1, int(math.sqrt(n)+1)):
        if(n%i==0):
            ans.append(i)
            ans.append(n//i)
    ans = sorted(list(dict.fromkeys(ans)))
    if(ans[-1]==n):
        ans = ans[:-1]
    return ans


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

Solution (Python):
from copy import deepcopy as dp
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

a_sum = [0]
for i in a:
    if a_sum[-1] + i > 10 ** 9:
        break
    a_sum.append(a_sum[-1] + i)

b_sum = [0]
for i in b:
    if b_sum[-1] + i > 10 ** 9:
        break
    b_sum.append(b_sum[-1] + i)

class binarySearch(object):

    def __init__(self, target):
        self.target = dp(target)
        self.target.append(10**18)

    def set(self, value):
        self.value = value

    def search(self):
        self.lower, self.upper = 0, len(self.target) - 1
        while self.upper != self.lower+1:
            next = (self.upper + self.lower) // 2
            if self.target[next] > self.value:
                self.upper = next
            else:
                self.lower = next
        return self.lower


test = binarySearch(b_sum)

ans = 0
for i, a_time in enumerate(a_sum):
    rest = k - a_time
    if rest >= 0:
        test.set(rest)
        ans = max(i + test.search(), ans)
    else:
        break

print(ans)

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

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

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


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

Solution (Python):
from collections import defaultdict, deque
import sys
import heapq
import bisect
import itertools
import queue
import copy
import time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7

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

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

def inpl_str(): return list(sys.stdin.readline().split())

N, M, K = inpl()
A = [0]
B = [0]
A += inpl()
B += inpl()
for i in range(N):
    A[i+1] += A[i]
for i in range(M):
    B[i+1] += B[i]

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

Solution (Python):
from collections import defaultdict, deque
import sys
import heapq
import bisect
import itertools
import queue
import copy
import time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7

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

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

def inpl_str(): return list(sys.stdin.readline().split())

N, M, K = inpl()
A = [0]
B = [0]
A += inpl()
B += inpl()
for i in range(N):
    A[i+1] += A[i]
for i in range(M):
    B[i+1] += B[i]
ans = 0
j = 0
for i in range(N, -1, -1):
    while (j <= M) and (A[i] + B[j] <= K):
        ans = max(ans, i+j)
        j += 1
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_sum_list = [0]
B_sum_list = [0]

for i in range(0,N):
    A_sum_list.append(A_sum_list[i]+A_list[i])
for i in range(0,M):
    B_sum_list.append(B_sum_list[i]+B_list[i])
time = 0
number = 0
j = M

for i in range(0,N+1):
    if A_sum_list[i] > K:
        break 
    while K - A_sum_list[i] < B_sum_list[j]: 
        j -= 1
    number = max(number, i+j)
print(number)

Solution (Python):
import numpy as np
n,m,k = map(int,input().split())
a = np.array([int(i) for i in input().split()], dtype='int64')
b = np.array([int(i) for i in input().split()], dtype='int64')


a_c = np.zeros(n+1,dtype='int64')
a_c[1:] = np.cumsum(a)

b_c = np.zeros(m+1,dtype='int64')
b_c[1:] = np.cumsum(b)

a_c = a_c[a_c <= k]
b_c = b_c[b_c <= k]

ans_l = np.searchsorted(b_c, k - a_c, side='right') - 1
ans_l += np.arange(len(a_c))
print(ans_l.max())

Solution (Python):
'''ABC172 C'''
import numpy as np
n,m,k = map(int,input().split())
a = np.array([int(i) for i in input().split()], dtype='int64')
b = np.array([int(i) for i in input().split()], dtype='int64')

a_c = np.zeros(n+1,dtype='int64')
a_c[1:] = np.cumsum(a)

b_c = np.zeros(m+1,dtype='int64')
b_c[1:] = np.cumsum(b)

a_c = a_c[a_c <= k]
b_c = b_c[b_c <= k]
ans = 0
for i,ai in enumerate(a_c):
    n = np.searchsorted(b_c, k - ai, side = 'right')
    ans = max(i + n-1, ans)
print(ans)

Solution (Python):





def solve(ls1, ls2, k):
    n, m = len(ls1), len(ls2)

    
    for i in range(n - 1):
        ls1[i + 1] += ls1[i]

    for i in range(m - 1):
        ls2[i + 1] += ls2[i]
    ls1 = [0] + ls1
    ls2 = [0] + ls2

    
    
    

    
    for j in range(m + 1)[::-1]:
        if ls2[j] <= k:
            J = j
            break
    ij_max = J

    
    I = 0
    while I <= n and J >= 0:
        while I <= n and ls1[I] + ls2[J] <= k:
            I += 1
        ij_max = max(ij_max, I + J - 1)
        J -= 1

    return ij_max


def main(istr, ostr):
    n, m, k = list(map(int, istr.readline().strip().split()))
    ls1 = list(map(int, istr.readline().strip().split()))
    ls2 = list(map(int, istr.readline().strip().split()))
    result = solve(ls1, ls2, k)
    print(result, file=ostr)


if __name__ == "__main__":
    import sys

    main(sys.stdin, sys.stdout)

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

Solution (Python):
n, m, k = map(int, input().split(' '))
list_a = list(map(int, input().split(' ')))
list_b = list(map(int, input().split(' ')))
 
a_sum=[list_a[0]]
for i in range(1, n):
  a_sum.append(list_a[i]+a_sum[i-1])
  
b_sum=[list_b[0]]
for i in range(1, m):
  b_sum.append(list_b[i]+b_sum[i-1])

  
ans=0 
if (a_sum[0]>k) and (b_sum[0]>k):
  print(0)
else:
  for j in range(m):
    if b_sum[j]<=k:
      ans=max(ans, j+1)
  j=m-1
  for i in range(n):
    if a_sum[i]<=k:
      ans=max(ans, i+1)
      while a_sum[i] + b_sum[j] > k and j>0:
        j-=1
      if a_sum[i]+b_sum[j]<=k:
        ans=max(ans, i+j+2)
  print(ans)

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

n, m, k = map(int, input().split())
(*a,) = accumulate(map(int, input().split()))
(*b,) = accumulate(map(int, input().split()))
a = (0,) + tuple(i for i in a if i <= k)
b = tuple(i for i in b if i <= k)
print(max(i + bisect(b, k - a[i]) for i in range(len(a))))

Solution (Python):
n,m,k=map(int,raw_input().split())
a=map(int,raw_input().split())
b=map(int,raw_input().split())
cnt1=0
cnt2=0
a1=[0]
b1=[0]
for i in range(n):
    a1.append(a1[-1]+a[i])
for i in range(m):
    b1.append(b1[-1]+b[i])
ans=0
j=m
for i in range(n+1):
    if a1[i]>k:
        break
    while b1[j]>k-a1[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()))

Asum_li = [0]
Asum = 0
Bsum_li = [0]
Bsum = 0

for A_ in A:
    Asum = Asum + A_
    Asum_li.append(Asum)

for B_ in B:
    Bsum = Bsum + B_
    Bsum_li.append(Bsum)

cnt_max = 0
cnt_b = M

for cnt_a in range(N+1):

    if Asum_li[cnt_a] > K : break

    while (Bsum_li[cnt_b] + Asum_li[cnt_a]) > K:
        cnt_b = cnt_b - 1
        if cnt_b < 0: break

    if (cnt_max < cnt_a + cnt_b): cnt_max = cnt_a + cnt_b


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

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_accumulate_cost = [0]
lastCost = 0
for i in range(N):
    lastCost += A[i]
    A_accumulate_cost.append(lastCost)

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

max_num = 0
p = M
for i in range(N+1):
    A_cost = A_accumulate_cost[i]
    if A_cost > K:
        break

    for j in range(p, -1, -1):
        if A_cost + B_accumulate_cost[j] <= K:
            p = j
            if i + j > max_num:
                max_num = i+j
            break

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_arr = [0] * n
a_arr[0] = a[0]
b_arr = [0] * m
b_arr[0] = b[0]


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


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

a_arr.insert(0, 0)
b_arr.insert(0, 0)


i_a_max = 0
for i in range(n+1):
    if a_arr[i] > k:
        break
    else:
        i_a_max = i


i_b = 0
for i in range(m+1):
    if b_arr[i] <= k:
        i_b = i
    else:
        break


score = []

for i_a in range(i_a_max + 1):
    while(True):
        if a_arr[i_a] + b_arr[i_b] <= k:
            break
        elif i_b == 0:
            break
        else:
            i_b -= 1
    score.append(i_a + i_b)
    

print(max(score))

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

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

acum2 = [0]
for i in range(m):
    acum2.append(acum2[-1]+arr2[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 = 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 = list(map(int, input().split()))
b = list(map(int, input().split()))
min = 0
cnt = 0
for k in b:
    min += k
j = M
for i in range(N+1):
    while(j > 0 and min > K):
        j -= 1
        min -= b[j]
    if(min > K):
        break
    cnt = max(cnt, i + j)
    if(i == N):
        break
    min += a[i]
print(cnt)

Solution (Python):
def strToList(str,offset=0):
    res = [];
    for el in str.split(" "):
        if el!='':
            res.append(int(el)+offset)
    return res


[N,M,K] = strToList(input())
A = strToList(input())
B = strToList(input())

current_time = 0
current_value = 0
iA = 0
iB = 0

while iA<N:
    if current_time+A[iA]<=K:
        current_time+=A[iA]
        current_value+=1
        iA+=1
    else:
        break

max_value = current_value
iA-=1

while iA>-2 and iB<M:
    if current_time+B[iB]<=K:
        current_time+=B[iB]
        iB+=1
        current_value+=1
        if current_value>max_value:
            max_value=current_value
    else:
        current_time-=A[iA]
        iA-=1
        current_value-=1

print(max_value)

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 main():
    n,m,k = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    import itertools
    sum_a = list(itertools.accumulate(a))
    sum_b = list(itertools.accumulate(b))
    if sum_a[-1] + sum_b[-1] <= k:
        print(n+m)
        return
    if a[0] > k and b[0] > k:
        print(0)
        return

    for i in range(n):
        if sum_a[i] > k:
            break

    s_a = i - 1
    if sum_a[-1] <= k:
        s_a = n-1
    now_sum = 0
    if s_a >= 0:
        now_sum = sum_a[s_a]
    for i in range(m):
        if now_sum + sum_b[i] > k:
            break
    s_b = i - 1
    ans = s_a + 1 + s_b + 1
    now_sum = 0
    for a_i in range(s_a-1, -2, -1):
        for b_i in range(s_b+1,m):
            if a_i < 0:
                now_sumtime = sum_b[b_i]
            else:
                now_sumtime = sum_a[a_i] + sum_b[b_i]

            if b_i == m-1 and now_sumtime <= k:
                now_sum = a_i + m + 1
                break
            if now_sumtime > k:
                now_sum = a_i + b_i + 1
                break
        s_b = b_i-1
        ans = max(ans, now_sum)
    print(ans)

if __name__=='__main__':
    main()

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

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

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

if __name__ == "__main__":
    resolve()

Solution (Python):
def bs(k, m):
    i = -1
    pas = 1<<30
    while pas:
        if i+pas < m and u[i+pas] <= k:
            i += pas
        pas //= 2
    return i+1

n, m, k = map(int, input().split())
v = list(map(int, input().split()))
u = list(map(int, input().split()))
for i in range(1, n):
    v[i] += v[i-1]
for i in range(1, m):
    u[i] += u[i-1]
ans = bs(k, m)
for i in range(n):
    if v[i] <= k:
        ans = max(ans, bs(k-v[i], m) + i+1)
print(ans)

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

a, 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 = 0
b = 0
a_time = 0
b_time = 0
max_read = 0

for i in range(m):
    if b_time + B[i] > k:
        break
    else:
        b_time += B[i]
else:
    i += 1
b = i
max_read = b

for i in range(n):
    if a_time + A[i] > k:
        break
    
    a_time += A[i]
    a += 1
    if a_time + b_time <= k:
        max_read = max(max_read, a + b)
        continue
    else:
        while(a_time + b_time > k):
            b -= 1
            if b < 0:
                break
            b_time -= B[b]
        max_read = max(max_read, a + b)

print(max_read)

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()]
ca=[0]*(n+1)
ca[1]=a[0]
for i in range(n):
  ca[i+1]=ca[i]+a[i]
cb=[0]*(m+1)
cb[1]=b[0]
for i in range(m):
  cb[i+1]=cb[i]+b[i]
j=m
ans=0
for i in range(n+1):
  t=ca[i]
  while j>=0:
    if t+cb[j]>k:
      j-=1
    else:
      ans=max(ans,i+j)
      break
print(ans)

Solution (Python):

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


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

    tmp_time = 0
    last_i = -1
    for i in range(N):
        if tmp_time + A[i] <= K:
            tmp_time += A[i]
            last_i = i
        else:
            break

    last_j = -1
    for j in range(M):
        if tmp_time + B[j] <= K:
            tmp_time += B[j]
            last_j = j
        else:
            break

    ans = last_i + last_j + 2
    now = ans
    while last_i >= 0:
        tmp_time -= A[last_i]
        now -= 1
        last_i -= 1

        while last_j + 1 < M and tmp_time + B[last_j + 1] <= K:
            tmp_time += B[last_j + 1]
            last_j += 1
            now += 1

        ans = max(ans, now)

    print(ans)


def main():
    solve()


if __name__ == '__main__':
    main()

Solution (Python):
from itertools import accumulate
from bisect import bisect_left,bisect_right

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

    result = 0
    for i in range(n+1):
        tmp = k - a[i]
        if tmp < 0:
            continue
        tmpNum = i + bisect_right(b, tmp) - 1
        if tmpNum > result:
            result = tmpNum

    print(result)       


if __name__ == "__main__":
    main()