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

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

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

print(ans)

Solution (Python):
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 bisect import bisect_right
from itertools import accumulate

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

a_book = [0] + list(accumulate([int(x) for x in input().split()]))
b_book = [0] + list(accumulate([int(x) for x in input().split()]))

check = {}

max_books = 0

for i, a in enumerate(a_book):
    if a > K:
        break

    b_pos = bisect_right(b_book, K - a)

    if max_books < b_pos - 1 + i:
        max_books = b_pos - 1 + i

print(max_books)

Solution (Python):
from itertools import accumulate
from bisect import bisect_right
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
Acc=list(accumulate(B))
ans=0
time=0
a_cnt=0
for a in A:
    remain=k-time
    if remain<0:
        break
    b_cnt=bisect_right(Acc,remain)
    ans=max(ans,a_cnt+b_cnt)
    time+=a
    a_cnt+=1
remain=k-time
if remain>=0:
    b_cnt=bisect_right(Acc,remain)
    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()))

asum=[0]
bsum=[0]

for i in range(n):
  asum.append(asum[i]+A[i])
  
for j in range(m):
  bsum.append(bsum[j]+B[j])

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

Solution (Python):
n,m,k=[int(x) for x in input().rstrip().split()]
a=[int(x) for x in input().rstrip().split()]
b=[int(x) for x in input().rstrip().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=0

for i in range(n+1):
  
  if A[i]>k:
    break
  nokori=k-A[i]

  while(B[j]<=nokori and j<m):
    j+=1

  if nokori<B[j]:
    j-=1
    
  ans=max(ans,i+j)
print(ans)

Solution (Python):
from bisect import bisect_right


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

    CUSUM_A = [0] * (N+1)
    CUSUM_B = [0] * (M+1)

    for i, a in enumerate(A):
        CUSUM_A[i+1] = CUSUM_A[i] + a

    for i, b in enumerate(B):
        CUSUM_B[i+1] = CUSUM_B[i] + b


    ans = 0
    for i, a in enumerate(CUSUM_A):
        rest = K - a
        if rest < 0:
            continue

        j = bisect_right(CUSUM_B, rest) - 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()))
t = 0
sum_a = [0]
for i in range(n):
  if t + a[i] <= k:
    t += a[i]
    sum_a.append(t)
  else:
    break
sum_b = [0]
t = 0
for i in range(m):
  if t + b[i] <= k:
    t += b[i]
    sum_b.append(t)
  else:
    break
ans = []
j = 0
for i in range(len(sum_a)):
  while sum_a[i] + sum_b[len(sum_b) - j - 1] > k:
    j += 1
  ans.append(i + len(sum_b) - j - 1)
print(max(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=[int(x) for x in input().rstrip().split()]
a=[int(x) for x in input().rstrip().split()]
b=[int(x) for x in input().rstrip().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
  nokori=k-A[i]

  while(nokori<B[j] and 0<=j):
    j-=1

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

Solution (Python):
import copy

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

asum = [0]
bsum = [0]
tmp = 0
for i in range(n):
    tmp += a[i]
    asum.append(tmp)
tmp = 0
for i in range(m):
    tmp += b[i]
    bsum.append(tmp)


ans = 0
nb = copy.deepcopy(m)
for na in range(n+1):
    res = k - asum[na]
    if res < 0:
        break
    flg = True
    while flg:
        if bsum[nb] > res:
            nb -= 1
            continue
        ans = max(ans, na+nb)
        break
print(ans)

Solution (Python):
from bisect import bisect_right
import numpy as np
N, M, K = map(int, input().split())
A = np.array([0] + list(map(int, input().split())))
B = np.array([0] + list(map(int, input().split())))

if A.sum() + B.sum() <= K:
    print(N + M)
    exit()

cumsum_A = A.cumsum()
cumsum_B = B.cumsum()



ans = 0
for num_A in range(len(cumsum_A)):
    t = cumsum_A[num_A]
    if t > K:
        continue
    num_B = bisect_right(cumsum_B, K - t) - 1
    
    ans = max(ans, num_A + num_B)
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 = [0]+a
for i in range(1,n+1):
    a[i] += a[i-1]
b = [0]+b
for i in range(1,m+1):
    b[i] += b[i-1]

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 = list(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):
  if k < a[i] + asum[i]:
    break
  asum.append(a[i] + asum[i])
for i in range(m):
  if k < b[i] + bsum[i]:
    break
  bsum.append(b[i] + bsum[i])

ans = 0
b_count = len(bsum)-1
for a_count in range(len(asum)):
  while asum[a_count] + bsum[b_count] > k:
    b_count -= 1
  ans = max(ans, a_count + b_count)
print(ans)

Solution (Python):
import bisect
n, m, k = list(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):
  if k < a[i] + asum[i]:
    break
  asum.append(a[i] + asum[i])
for i in range(m):
  if k < b[i] + bsum[i]:
    break
  bsum.append(b[i] + bsum[i])

ans = 0
for i in range(len(asum)):
  ans = max(ans, i + bisect.bisect(bsum, k-asum[i]) - 1)
print(ans)

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

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

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

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

    while b_sum[j] > K - a_sum[i]:
        j-=1
    ans = max(ans, i+j)
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()))

cost = 0
cnt = 0

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

ans = 0

b_cnt = m

for a_cnt in range(n+1):
    if a[a_cnt] > k:
        continue

    while b[b_cnt] > k - a[a_cnt]:
        b_cnt -= 1

    ans = max(ans, a_cnt + b_cnt)

print(ans)

Solution (Python):
from itertools import accumulate
from bisect import bisect_right
def solve():
    N,M,K = map(int,input().split())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))

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

    ans = 0
    for i in range(N+1):
        if a[i] > K:
            break
        b_max = K - a[i]
        cnt = i + bisect_right(b,b_max) - 1
       
        ans = max(ans,cnt)
        
    print(ans)
    
if __name__ == '__main__':
    solve()

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

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

print(ans)

Solution (Python):
from bisect import bisect_right
from time import time

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

a_book = [0]
for index, i in enumerate(input().split(), 1):
    if a_book[index-1] + int(i) <= K:
        a_book.append(a_book[index-1] + int(i))
    else:
        N = index - 1
        break

b_book = [0]
for index, i in enumerate(input().split(), 1):
    if b_book[index-1] + int(i) <= K:
        b_book.append(b_book[index-1] + int(i))
    else:
        M = index - 1
        break

check = {}

max_books = 0

for i, a in enumerate(a_book):
    b_pos = bisect_right(b_book, K - a)

    if max_books < b_pos - 1 + i:
        max_books = b_pos - 1 + i

print(max_books)

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

Solution (Python):
import bisect

def cumsum(a):
   r = [0]
   for v in a:
      r.append(r[-1] + v)
   return r

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


a_cumsum = cumsum(a)
b_cumsum = cumsum(b)

ans = 0


for a_num, v in enumerate(a_cumsum):
    tmp = 0
    if k >= v:
        b_num = bisect.bisect_right(b_cumsum, k-v) -1
        
        tmp = a_num + b_num
    ans = max(ans,tmp)

print(ans)

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

from collections import deque

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

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

accum_a = [0]
accum_b = [0]

for a_i in range(0, len(an)):
    a_i = accum_a[-1] + an[a_i]
    if a_i > k:
        break
    accum_a.append(a_i)

for b_i in range(0, len(bn)):
    i_ = accum_b[-1] + bn[b_i]
    if i_ > k:
        break
    accum_b.append(i_)

ans = 0
for a_i in range(len(accum_a)):

    sumCandidate = accum_a[a_i]
    rest = k - sumCandidate

    j = (len(accum_b)) // 2
    finalBIndex = j
    left = -1
    right = len(accum_b)
    while right - left > 1:
        mid = left + (right - left) // 2

        if accum_b[mid] > rest:
            right = mid
        else:
            left = mid

    ans = max(ans, a_i + right - 1)

print(ans)

Solution (Python):
n, m, k = map(int, input().split())
a_list = list(map(int, input().strip().split()))
b_list = list(map(int, input().strip().split()))

a, b = [0], [0]
for i in range(n):
    a.append(a[i] + a_list[i])
for j in range(m):
    b.append(b[j] + b_list[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):
import sys, os, math, bisect, itertools, collections, heapq, queue

from decimal import Decimal
from collections import defaultdict, deque



sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)


MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M, K = il()
    
    A = list(itertools.accumulate([0] + il()))
    B = list(itertools.accumulate(([0] + il())))

    
    ret, m = 0, M
    for n in range(N + 1):
        if A[n] > K:
            break

        while B[m] > K - A[n]:
            m -= 1
        ret = max(ret, n + m)
    print(ret)


if __name__ == '__main__':
    main()

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

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

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

print(ans)

Solution (Python):
N, M, K=map(int, input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
A=[0]+A
B=[0]+B
import numpy as np
a=np.cumsum(A)
b=np.cumsum(B)

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

Solution (Python):

from itertools import accumulate
from collections import deque
import bisect

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

cnt = 0

a_c = list(accumulate(list(a)))
b_c = list(accumulate(list(b)))
result = []

for i in range(n+1):
    if a_c[i] > k:
        continue
    b_idx = bisect.bisect_left(b_c,k-a_c[i]+1)
    result.append(i+b_idx-1)
    
print(max(result))

Solution (Python):
import sys
input = sys.stdin.readline
import bisect
def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    cum_a = [0] * (N + 1)
    for i in range(N):
        cum_a[i+1] = cum_a[i] + A[i]
    cum_b = [0] * (M + 1)
    for i in range(M):
        cum_b[i+1] = cum_b[i] + B[i]
    ans = 0
    for i in range(N+1):
        rest = K - cum_a[i]
        if rest < 0:break
        b_idx = bisect.bisect_right(cum_b, rest)
        ans = max(ans, i + b_idx - 1)
    print(ans)
if __name__ == "__main__":
    main()

Solution (Python):
from bisect import bisect_right
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
for i in range(n-1):
    a[i+1]+=a[i]
for i in range(m-1):
    b[i+1]+=b[i]
a=[0]+a
ans=0
for i in range(n+1):
    if a[i]>k:
        continue
    idx=bisect_right(b,k-a[i])
    ans=max(ans,idx+i)
print(ans)

Solution (Python):
import bisect
n, m, k = list(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):
  if k < a[i] + asum[i]:
    break
  asum.append(a[i] + asum[i])
for i in range(m):
  if k < b[i] + bsum[i]:
    break
  bsum.append(b[i] + bsum[i])

ans = 0
for i in range(len(asum)):
  tmp = i + bisect.bisect(bsum, k-asum[i]) - 1
  if ans < tmp:
    ans = tmp
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[-1]+A[i])
for j in range(m):
    b.append(b[-1]+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 numpy as np

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

A = np.array(A).cumsum()
B = np.array(B).cumsum()

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):
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a2 = [0]
b2 = [0]
for i in range(n):
    a2.append(a2[i]+a[i])
for i in range(m):
    b2.append(b2[i]+b[i])
ans = 0
cnt = m
for i in range(n+1):
    if a2[i] > k:
        break
    sm = 0
    while b2[cnt] > k-a2[i]:
        cnt -= 1
    ans = max(cnt+i, ans)
print(ans)

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

sumAL = [0]
for i in range(len(listA)):
    sumAL.append(sumAL[-1]+listA[i])
sumBL = [0]
for i in range(len(listB)):
    sumBL.append(sumBL[-1]+listB[i])
ib = len(sumBL)-1
bookMax = 0
for ia in range(len(sumAL)):
    while ib > -1:
        if sumBL[ib] <= k-sumAL[ia]:
            if bookMax < ia+ib:
                bookMax = ia+ib
            break
        ib-=1
print(bookMax)

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)
b = [0]*(m+1)
for i in range(n):
    a[i+1] = a[i] + A[i]
    
for i in range(m):
    b[i+1] = b[i] + B[i]

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

Solution (Python):
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
books = 0
for i in range(N+1):
	if sa[i] > k: break
	while sa[i] + sb[r] > k:
		r -= 1
	books = max(books, i+r)
print(books)

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

max_c = 0
c = 0
i = 0
j = 0

while i < n and k - a[i] >=0:
    k -= a[i]
    i += 1
    c += 1

while j < m and k - b[j] >=0:
    k -= b[j]
    j += 1
    c += 1


max_c = c


i -= 1

while i >= 0:
    k += a[i]
    c -= 1
    while j < m and k - b[j] >= 0:
        k -= b[j]
        c += 1
        j += 1
    max_c = max(c, max_c)
    i -= 1
print(max_c)

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

ans = 0
a_cum = [0] + list(itertools.accumulate(a))
b_cum = [0] + list(itertools.accumulate(b))

y = m  
for x in range(len(a_cum)):
    if a_cum[x] > k:
        break
    while b_cum[y] > k - a_cum[x]:
        y -= 1
    ans = max(ans, x + y)

print(ans)

Solution (Python):



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


max_count = 0
b_i = M
a_cums = [0]*(N+1)
b_cums = [0]*(M+1)
for i in range(1, N+1):
    if i>1:
        a_cums[i] = a_cums[i-1] + a_nums[i-1]
    else:
        a_cums[i] = a_nums[i-1]
for i in range(1, M+1):
    if i>1:
        b_cums[i] = b_cums[i-1] + b_nums[i-1]
    else:
        b_cums[i] = b_nums[i-1]

for i in range(N+1):
    if a_cums[i]<=K:
        while b_i>0 and a_cums[i]+b_cums[b_i]>K:
            b_i -= 1
        if i+b_i>max_count:
            max_count = i+b_i


print(max_count)

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]
for i,a in enumerate(A, 1):
    tmp = sum_A[i-1] + a
    if tmp <= K:
        sum_A.append(tmp)
        mark_A = i
    else:
        break
    
sum_B = [0]
for i,b in enumerate(B, 1):
    tmp = sum_B[i-1] + b
    if tmp <= K:
        sum_B.append(tmp)
        mark_B = i
    else:
        break
    
ans = 0
j = len(sum_B) - 1

for i,a in enumerate(sum_A):
    while sum_B[j] > K - a:
        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, 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
for i in range(n+1):
  if a[i] > k:
    break
  ans = max(ans,i+bisect.bisect(b,k-a[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()))

from itertools import accumulate
A = [0] + list(accumulate(a))
B = [0] + list(accumulate(b))

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

print(ans)

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


from itertools import accumulate
A = list(accumulate(a))
B = list(accumulate(b))

p(*A)
p(*B)

from bisect import bisect_right as br

ans = 0




A = [0] + A
for a, ka in enumerate(A):
  if ka > K: break

  b = br(B, K - ka) 
  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 = [0]
B = [0]

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

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

Solution (Python):
import bisect
import itertools
n,m,k = map(int,input().split())
A = [0]+list(map(int,input().split()))
B = [0]+list(map(int,input().split()))


a_cum = list(itertools.accumulate(A))
b_cum = list(itertools.accumulate(B))

ans=0



for a_i,a in enumerate(a_cum):
    if a>k:
        break
    
    b_i = bisect.bisect_right(b_cum,k-a)-1
    ans = max(ans,a_i+b_i)
print(ans)

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

Solution (Python):
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
n -= -1
m -= -1
a.insert(0, 0)
b.insert(0, 0)
for i in range(1, n): a[i] += a[i - 1]
for i in range(1, m): b[i] += b[i - 1]
ans = 0
for i in range(n):
    if a[i] > k: break
    lo, hi = 0, m - 1
    tmp = a[i]
    while hi - lo > 1:
        mid = lo + (hi - lo) // 2
        if tmp + b[mid] > k: hi = mid - 1
        else: lo = mid
    if tmp + b[hi] <= k: lo = hi
    ans = max(ans, i + lo)
print(ans)

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

import numpy as np
import bisect

nss = np.array([0] + ns).cumsum()
mss = np.array([0] + ms).cumsum()
mx = 0
for i in range(n + 1):
    if nss[i] > k:
        break
    j = bisect.bisect_right(mss, k - nss[i])
    if j > 0:
        j -= 1
    mx = max(mx, i + j)
print(mx)

Solution (Python):
import sys

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

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

nmax=0

Asum=list()
Asum.append(0)
Bsum=list()
Bsum.append(0)

imax_a = N
for i in range(N):
    s = Asum[i]+A[i]
    Asum.append(s)
    if s > K:
        imax_a = i+1
        break

imax_b = M
for i in range(M):
    s = Bsum[i]+B[i]
    Bsum.append(s)
    if s > K:
        imax_b = i+1
        break
        
for i in range(imax_a+1):
    for j in range(imax_b, -1, -1):
        time = Asum[i]+Bsum[j]
        
        if time <= K:
            imax_b = j

            if nmax < i+j:
                nmax = i+j
                

            break

print(nmax)

Solution (Python):

import sys


def binary_search(l, r, pred):
    while l < r:
        mid = (l + r) // 2
        if pred(mid):
            r = mid
        else:
            l = mid + 1
    return l


def solve(N: int, M: int, K: int, A: "List[int]", B: "List[int]"):
    ans = 0
    cA = [0] * (N + 1)
    cB = [0] * (M + 1)
    for i, a in enumerate(A):
        cA[i + 1] = cA[i] + a
    for i, b in enumerate(B):
        cB[i + 1] = cB[i] + b
    if cA[-1] + cB[-1] <= K:
        print(N + M)
        return

    def min_time(x):
        
        return min((cA[i] + cB[x - i] for i in range(N + 1) if 0 <= x - i <= M))

    ans = binary_search(0, N + M, lambda x: min_time(x) > K) - 1
    print(ans)
    return



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

best = 0

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()))
x,y=[0],[0]
for i in range(n):
    x.append(a[i]+x[i])
for j in range(m):
    y.append(b[j]+y[j])

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

Solution (Python):
from bisect import bisect_right

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

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




ans = 0
for i, s1 in enumerate(cumA):
    j = bisect_right(cumB, K - s1) - 1
    if j >= 0:
        s2 = cumB[j]
        assert s1 + s2 <= K
        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 = [0]
b = [0]
for i in range(len(A)):
    a.append(a[i] + A[i])

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





j_n = m
ans = 0

for i_n in range(len(a)):
    if a[i_n] > k:
        break

    while b[j_n] > k - a[i_n]:
        j_n -= 1

    ans = max(ans, i_n + j_n)

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])
    if a[i]+A[i]>K:
        break

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



    
ans =0
j = M

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

print(ans)

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

a, b = [0], [0]
for ai in A:
    a.append(a[-1] + ai)

for bi in B:
    b.append(b[-1] + bi)


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

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

print(max)

Solution (Python):
from itertools import accumulate
from bisect import bisect_right
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
a=list(accumulate(A))
b=list(accumulate(B))
book=bisect_right(b,K)
for i in range(N):
    if a[i]>K:
        break
    j=bisect_right(b,K-a[i])
    book=max(book,(i+1)+j)
print(book)