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):
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time


def I(): return int(input())
def S(): return input()
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def print_matrix(mat):
    for i in range(len(mat)):
        print(*['IINF' if v == IINF else "{:0=4}".format(v) for v in mat[i]])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False



def main():
    N, M, K = MI()
    A = LI()
    B = LI()
    ans = 0

    A = list(accumulate([0] + A))
    B = list(accumulate([0] + B))

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

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):

import sys

def solve(N: int, M: int, K: int, A: "List[int]", B: "List[int]"):
    weightA = 0
    len_A = N
    for idx, a in enumerate(A):
        if weightA + a > K:
            len_A = idx
            break
        else:
            weightA += a
    max_count = current_count = len_A

    weightB = 0
    for b in B:
        if len_A==0 and weightA + weightB + b > K:
            break

        elif weightA + weightB + b <= K:
            weightB += b
            current_count += 1

        else:
            while weightA + weightB + b > K:
                len_A -= 1
                weightA -= A[len_A]
                current_count -= 1
                if len_A == 0:
                    break

            if weightA + weightB + b <= K:
                weightB += b
                current_count += 1
        max_count = max(max_count, current_count)

    print(max_count)
    return



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

if __name__ == '__main__':
    main()

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


n,m,k = map(int, input().split())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))

al_sums = list(accumulate(al))
bl_sums = list(accumulate(bl))

ans = 0
for i in range(0,n+1):
    if i == 0: 
        a_sum = 0
    else:
        a_sum = al_sums[i-1]
    if a_sum > k: 
        continue
    cnt = bisect_right(bl_sums, k-a_sum)
    curr_ans = i+cnt
    ans = max(ans,curr_ans)

print(ans)

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_sum[i] + a[i])

b_sum = [0]
for i in range(m):
    b_sum.append(b_sum[i] + b[i])
b_sum.append(10**20)
ans = 0

for i in range(n+1):
    t = a_sum[i]
    l = 0
    r = len(b_sum)
    
    while l+1<r:
        
        c = (l + r) // 2
        
        
        if t+b_sum[c]<=k:
            l = c
        
        
        else:
            r = c
    
    if a_sum[i]+b_sum[l]<=k:
        ans = max(ans,i+l)
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()))

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

Bsum = [0]
for j in range(M):
    Bsum.append(Bsum[j] + B[j])

ans = 0
for i in range(N+1):
    if Asum[i] > K:
        continue
    tmp = K - Asum[i]
    j = bisect.bisect_right(Bsum, tmp) - 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_added=[0]
b_added=[0]
for i in range(n):
    a_added.append(a_added[i]+a[i])
for i in range(m):
    b_added.append(b_added[i]+b[i])

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

Solution (Python):


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,m,k = LI()
a = LI()
b = LI()
a = [0] + list(accumulate(a))
b = [0] + list(accumulate(b))
ans = 0
for i in range(n+1):
    r = br(b, k-a[i])
    if r == 0 and a[i] <= k:
        ans = max(ans, i + r - 1)
    elif r != 0:
        ans = max(ans, i + r - 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 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):
A_len, B_len, K = map(int, input().split(' '))


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




A_acc = []
for idx_A in range(A_len): 
  if(idx_A == 0):
    A_acc.append(A[0])
  else:
    A_acc.append(A_acc[idx_A - 1] + A[idx_A])
A_acc.insert(0, 0)
    
B_acc = []
for idx_B in range(B_len):
  if(idx_B == 0):
    B_acc.append(B[0])
  else:
    B_acc.append(B_acc[idx_B - 1] + B[idx_B])
B_acc.insert(0, 0)



max_num = 0
left_time = K
b_num = B_len
for a_num in range(A_len + 1):
  left_time = K - A_acc[a_num]
  
  if(left_time < 0):
    break
  
  while(left_time - B_acc[b_num] < 0):
    
    
    b_num -= 1
    
  
  
  max_num = max(max_num, (a_num + b_num))
  
  
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,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
import bisect
n,m,k=map(int,input().split())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]

A=list(accumulate(a))
B=list(accumulate(b))
ans=bisect.bisect_right(B,k)
for i in range(len(a)):
    r = (k-A[i])
    if r<0:
        break
    
    
    ans=max(ans,i+1+bisect.bisect_right(B,r))
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])

j,ans=m,0
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())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
sAs = [0]
s = 0
for A in As:
  s += A
  sAs.append(s)
sBs = [0]
s = 0
for B in Bs:
  s += B
  sBs.append(s)
rs = []
for n in range(0, N+1):
  kA = sAs[n]
  if kA > K:
    continue
  kB = K-kA
  m = bisect.bisect(sBs, kB)-1
  
  r = n+m
  rs.append(r)
r = max(rs)
print(r)

Solution (Python):

N, M, K = map(int, input().split())
A = [0] + list(map(int, input().split())) + [10**13]
B = [0] + list(map(int, input().split())) + [10**13]
sum_t = 0
cumsumA = [0]
cumsumB = [0]
ansA = N
ansB = 0
tmp = 0
for i in range(1, N+1):
    tmp = tmp + A[i]
    if tmp > K:
        ansA = i-1
        break
    cumsumA += [tmp]
tmp = 0
for i in range(1, M+1):
    tmp = tmp + B[i]
    if tmp > K:
        break
    cumsumB += [tmp]
j = 0
ans = 0
for i in range(ansA, -1, -1):
    t = cumsumA[i] + cumsumB[j]
    while True:
        tmp = B[j+1]
        if tmp + t <= K:
            t += tmp
            j += 1
        else:
            break
    ans = max(ans, i + j)
print(ans)

Solution (Python):
import numpy as np

N, M, K = list(map(int, input().split()))
A = list(map(int, [0] + input().split()))
B = list(map(int, [0] + input().split()))
cost = 0
cumsum_a = np.cumsum(A)
cumsum_b = np.cumsum(B)

num_book = 0
max_a = 0
ind_b = 0
max_b = 0
for i in range(1, N + 1):
    if cumsum_a[i] <= K:
        max_a = i
    else:
        break

for i in range(1, M + 1):
    if cumsum_b[i] <= K:
        max_b = i
    else:
        break

for i in range(max_a, -1, -1):
    for j in range(ind_b, max_b+1):
        if cumsum_b[j] + cumsum_a[i] <= K:
            
            num_book = max(i + j, num_book)
            ind_b = j
        else:
            break
print(num_book)

Solution (Python):
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
aa=[0]*n
ba=[0]*m
aa[0]=a[0]
ba[0]=b[0]
for i in range(1,n):
  aa[i]=aa[i-1]+a[i]
for i in range(1,m):
  ba[i]=ba[i-1]+b[i]
aa=[0]+aa
ba=[0]+ba
import bisect as bi
ax=bi.bisect_right(aa,k)-1
ans=0
for i in range(ax+1):
  kk=k-aa[ax-i]
  bx=bi.bisect_right(ba,kk)-1
  t=ax+bx-i
  ans=max(ans,t)
print(ans)

Solution (Python):
from collections import deque
import sys
N, M, K = map(int,input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a, b  = [0], [0]
for n in range(N):
    a.append(a[n]+A[n])
    
for m in range(M):
    b.append(b[m]+B[m])
    
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
from itertools import accumulate
from bisect import bisect_right

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


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

    A_ = [0] + list(accumulate(A))
    B_ = [0] + list(accumulate(B))

    init = bisect_right(A_, k)
    res = init - 1
    for i in range(init):
        t = k - A_[init - i - 1]
        idx = bisect_right(B_, t)
        res = max(res, init - i - 1 + idx - 1)

    print(res)


if __name__ == '__main__':
    resolve()

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

da = [0 for _ in range(N+1)]
for i in range(N):
    da[i+1] = da[i] + a[i]
db = [0 for _ in range(M+1)]
for i in range(M):
    db[i+1] = db[i] + b[i]

ans = 0; j = M
for i in range(N+1):
    if da[i] > K:
        break
    while db[j] > K - da[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()))
def ruiseki(n, A):
    "長さnの数列Aの累積和を返す　ただし[0] = 0"
    res = [0]*(n+1)
    for i in range(n):
        res[i+1] = res[i] + A[i]
    return res
sa = ruiseki(n,A)
sb = ruiseki(m,B)

ans = 0
j = m
for i,a in enumerate(sa):
    
    while j >= 0 and a+sb[j] > k:
        j -= 1
    if j < 0:break
    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_cs = [0] * (n + 1)
b_cs = [0] * (m + 1)

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

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

    if a_cs[i] + b_cs[j] <= k:
        ans = max(ans, i + j)

print(ans)

Solution (Python):
def resolve():
    '''
    code here
    '''

    N, M, K = [int(item) for item in input().split()]
    As = [int(item) for item in input().split()]
    Bs = [int(item) for item in input().split()]

    res = 0
    time = 0

    memo_A = [0]
    for i in range(N):
        memo_A.append(As[i]+memo_A[-1])

    memo_B = [0]
    for i in range(M):
        memo_B.append(Bs[i]+memo_B[-1])

    res = 0
    j = M
    for i, av in enumerate(memo_A):
        if av > K:
            break
        else:
            
            while av + memo_B[j] > K:
                j -= 1
            res = max(res,j+i)

    print(res)

if __name__ == "__main__":
    resolve()

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):
import bisect

n, m, k = map(int, input().split())
a = [int(_) for _ in input().split()]
b = [int(_) for _ in input().split()]

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

a = [0] + a
b = [0] + b

ans = 0

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

Solution (Python):


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

    def accumulate(a):
        s = 0
        yield s
        for x in a:
            s += x
            yield s

    A = accumulate(A)
    *B, = accumulate(B)

    ans = 0
    j = M

    for i, x in enumerate(A):
        if x > K: break
        while B[j] > K - x: 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()))

sumA=[0]
sumB=[0]


for i in range(N):
  sumA.append(sumA[-1]+A[i])
for i in range(M):
  sumB.append(sumB[-1]+B[i])

  
total=0
startB=len(sumB)-1
for a in range(len(sumA)):
  for b in range(startB,-1,-1):
    if sumA[a]+sumB[b]<=K:
      total=max(total,a+b)
      startB=b
      break
  if sumA[a]>K:
    break
    
print(total)

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

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

ans = 0
from bisect import bisect_right
for i in range(N+1):
    zan = K - AL[i]
    if zan < 0:
        break
    ind = bisect_right(BL, zan) - 1
    ans = max(ans, i + ind)

print(ans)

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

sum_alist=[0]
for a in alist:
  sum_alist.append(sum_alist[-1]+a)
sum_blist=[0]
for b in blist:
  sum_blist.append(sum_blist[-1]+b)
  
index_b=M
answer=0
for i in range(N+1):
  if sum_alist[i]>K:
    break
    
  while sum_alist[i]+sum_blist[index_b]>K:
    index_b-=1
    
  
  answer=max(answer,i+index_b)
  
print(answer)

Solution (Python):


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

    def accumulate(a):
        s = 0
        yield s
        for x in a:
            s += x
            yield s

    *A, = accumulate(A)
    *B, = accumulate(B)

    ans = 0
    j = M

    for i, x in enumerate(A):
        if x > K: break
        while B[j] > K - x: j -= 1
        ans = max(ans, i + j)

    print(ans)


if __name__ == '__main__':
    main()

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=np.cumsum(np.array([0]+a))
B=np.cumsum(np.array(b))
ans=0
for i in range(n+1):
    if A[i]>k:
        break
    t=k-A[i]
    tmp=bisect.bisect_right(B,t)
    ans=max(ans, i+tmp)
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()))

    AReqTime = [0]
    BReqTime = [0]

    for i in range(N):
        AReqTime.append(AReqTime[i] + A[i])
    for i in range(M):
        BReqTime.append(BReqTime[i] + B[i])

    j = M
    answer = 0

    for i in range(N + 1):
        if(AReqTime[i] > K):
            break

        while BReqTime[j] > K - AReqTime[i]:
            j = j - 1

        answer = max(i + j, answer)

    print(answer)

if __name__ == "__main__":
    main()

Solution (Python):
def c_tsundoku():
    from itertools import accumulate
    N, M, K = [int(i) for i in input().split()]
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]

    a_cumsum, b_cumsum = [0] + list(accumulate(A)), [0] + list(accumulate(B))

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

print(c_tsundoku())

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]
atemp = 0
btemp = 0
for i in range(N):
    atemp += A[i]
    Asum.append(atemp)
for i in range(M):
    btemp += B[i]
    Bsum.append(btemp)

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

print(ans)

Solution (Python):
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(1, n + 1):
    A[i] = A[i - 1] + a[i - 1]

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

ans = 0
best = m
for i in range(n + 1):
    for j in range(best, -1, -1):
        t = A[i] + B[j]
        if t <= k:
            ans = max(ans, i + j)
            best = j
            break
print(ans)

Solution (Python):
import bisect
from collections import deque

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

sa, sb = [0], [0]
s = 0
for i in range(n):
    s += a[i]
    if s > k:
        break
    sa.append(s)

s = 0
for i in range(m):
    s += b[i]
    if s > k:
        break
    sb.append(s)

ans = 0


for i in range(len(sa)):
    l = k - sa[i]
    if l < 0:
        break

    num = bisect.bisect_right(sb, l) - 1
    ans = max (ans, num+i)

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


sum_A = [0]
sum_B = [0]
for n in range(N):
    sum_A.append(sum_A[n]+A[n])
for m in range(M):
    sum_B.append(sum_B[m]+B[m])

max_j = M
max_book = 0
for i in range(N+1):
    
    if sum_A[i] > K:
        break
    for j in range(max_j,-1,-1):
        if sum_A[i]+sum_B[j] <= K:
            max_j = j
            break
    else:
        max_j = 0
    
    max_book = max(max_book, i+max_j)

print(max_book)

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

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

sum_alist=[0]
for i in range(N):
  sum_alist.append(sum_alist[-1]+alist[i])


sum_blist=[0]
for i in range(M):
  sum_blist.append(sum_blist[-1]+blist[i])


limit_a=bisect.bisect(sum_alist,K)


answer=0
for i in range(limit_a):
  a_sum=sum_alist[i]
  b_sum=K-a_sum
  pos_b=bisect.bisect(sum_blist,b_sum)
  
  answer=max(answer,i+pos_b-1)
  
print(answer)

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

acc_a = list(accumulate(a))
acc_b = list(accumulate(b))

ans = 0
for i, e in enumerate(acc_b):
    if e > k:
        break
    a_cnt = bisect_right(acc_a, k - e)
    ans = max(ans, i + a_cnt)

print(ans)

Solution (Python):
import bisect
from itertools import accumulate

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

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

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

con_sum_A = [0]*(N+1)
con_sum_B = [0]*(M+1)
for i in range(1, N+1):
    con_sum_A[i] = con_sum_A[i-1] + A[i-1]

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

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

Solution (Python):











import sys
def p(*_a):
  return
  _s=" ".join(map(str,_a))
  
  sys.stderr.write(_s+"\n")


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



from itertools import accumulate
C = list(accumulate(A))
D = list(accumulate(B))

p(*C)
p(*D)

ans = 0
d = len(D) - 1
for c in range(len(C)):
  if C[c] > K: break
  while True:
    if C[c] + D[d] <= K: break
    d -= 1

  ans = max(ans , c + d)

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

Solution (Python):
import sys
from itertools import accumulate
import bisect
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    N, M, K = readnums()
    A = list(readnums())
    B = list(readnums())

    aa = list(accumulate(A))
    bb = list(accumulate(B))
    ans = bisect.bisect_right(bb, K)
    for i in range(len(aa)):
        if aa[i] <= K:
            tmp = bisect.bisect_right(bb, K - aa[i]) + i + 1
        else:
            continue
        ans = max(ans, tmp)

    print(ans)


if __name__ == "__main__":
    main()

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

A,B=[0],[0]

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

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

ans=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_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])

max_count = 0
j = M
for i in range(N+1):
    if A_sum[i] > K:
        break

    while B_sum[j] + A_sum[i] > K:
        j -= 1
    max_count = max(max_count, i + j)
print(max_count)

Solution (Python):
def main():
    N, M, K = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    
    if a[0] > K and b[0] > K:
        return 0

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

if __name__ == '__main__':
    print(main())

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

    s = 0
    j = 0
    while j < len(B) and s + B[j] <= K:
        s += B[j]
        j += 1

    ans = cnt = j

    j -= 1
    for x in A:
        while j >= 0 and s + x > K:
            s -= B[j]
            j -= 1
            cnt -= 1
        if s + x > K:
            break
        s += x
        cnt += 1
        if ans < cnt:
            ans = cnt
    print(ans)


if __name__ == '__main__':
    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, 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 = N

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

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

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

AS = list(it.accumulate(A))
BS = list(it.accumulate(B))
AS.insert(0,0)
BS.insert(0,0)
max = 0
for i in range(N+1):
    a = AS[i]
    if a > K:
        continue
    if max - i > 0:
        j = max - i
    else:
        j = 0
    while j < M + 1:
        b = BS[j]
        if a + b > K:
            break
        if max < i + j:
            max = i + j
        j += 1

print(max)

Solution (Python):
from itertools import *
f=lambda:map(int,input().split())
g=lambda:[0]+[*accumulate(f())]
n,m,k=f()
A,B=g(),g()
a,j=0,m
for i in range(n+1):
  while j and B[j]>k-A[i]: j-=1
  if A[i]+B[j]<=k: a=max(a,i+j)
print(a)

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]*N, [0]*M

total = 0
for i in range(N):
    total += A[i]
    a[i] = total

a = [0] + a

total = 0
for i in range(M):
    total += B[i]
    b[i] = total

b = [0] + b

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):
import bisect

N, M, K = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

da = [0 for _ in range(N+1)]
for i in range(N):
    da[i+1] = da[i] + a[i]
db = [0 for _ in range(M+1)]
for i in range(M):
    db[i+1] = db[i] + b[i]

ans = 0
for i in range(N+1):
    if da[i] > K:
        break
    ans = max(ans, i + bisect.bisect_right(db, K-da[i]) - 1)
print(ans)

Solution (Python):

import sys


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)