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()))
ea=[0]
for i in range(n):
    ea.append(ea[i]+a[i])
eb=[0]
for i in range(m):
    eb.append(eb[i]+b[i])
tb=m
p=0
for i in range(n+1):
    while ea[i]+eb[tb]>k:
        if tb==0:
            break
        tb-=1
    if ea[i]+eb[tb]<=k:
        p=max(i+tb,p)
print(p)

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

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

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

for i in range(1, len(B)):
  B[i] += B[i - 1]
  
import bisect
ans = 0
for i in range(len(A)):
  
  rest = K - A[i]
  if rest < 0:
    continue
  
  b_read = bisect.bisect_right(B, rest) - 1
  if i + b_read > ans:
    ans = i + b_read
    
print(ans)

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

lia = [0]
lib = [0]
j = M
ans = 0

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

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

    while lib[j] > K-lia[i]:
        j -= 1
    ans = max(ans, i+j)

print(ans)

Solution (Python):
from itertools import accumulate
from bisect import bisect
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
A=list(accumulate(A,initial=0))
B=list(map(int,input().split()))
B=list(accumulate(B))

ans = 0
for i,a in enumerate(A):
  if a > k: break
  ans = max(ans,i + bisect(B,k-a))
print(ans)

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

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

ans = 0
j = M

for i in range(N + 1):
    if a[i] > K:
        break
    while 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()))

lia = [0]
lib = [0]
tmp = M
ans = 0

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

for i in range(N+1):
    kari = 0
    t = K - lia[i]
    kari += i

    if t<0:
        break
    elif t==0:
        ans = max(ans, i)
        break
    else:
        pass

    for j in range(tmp,-1,-1):
        if t<lib[j]:
            continue
        else:
            tmp = j
            kari += j
            ans = max(ans, kari)
            break

print(ans)

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce, lru_cache  
from fractions import gcd
import sys  

n, m, k = (int(x) for x in input().split())
A = list(int(x) for x in input().split())
B = list(int(x) for x in input().split())

accA = list(accumulate(A))
accB = list(accumulate(B))
ans = 0
for i in range(n):
    if accA[i] > k:
        break
    ans = max(ans, i + 1 + bisect_right(accB, k - accA[i]))
ans = max(ans, 0 + bisect_right(accB, k))
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 
for i in range(n + 1):
    if a[i] > k:
        break
    while  a[i] + b[m] > k:
        m -= 1
    ans = max(ans, i + m)
print(ans)

Solution (Python):

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
'''
with open('./b09.txt') as f:
    N, M, K = map(int, f.readline().split())
    A = list(map(int, f.readline().split()))
    B = list(map(int, f.readline().split()))
'''
A_cnt = 0
B_cnt = 0
ans = 0
nowK = K
for A_idx in range(N):
    if nowK < A[A_idx]:
        break
    ans += 1
    nowK -= A[A_idx]
    A_cnt += 1
for B_idx in range(M):
    if nowK < B[B_idx]:
        break
    ans += 1
    nowK -= B[B_idx]
    B_cnt += 1
tmp_ans = ans
finish = False
for i in range(A_cnt, 0, -1):
    nowK += A[i - 1]
    tmp_ans -= 1
    for j in range(B_cnt, M):
        if finish or nowK < B[j]:
            break
        nowK -= B[j]
        tmp_ans += 1
        B_cnt += 1
    ans = max(tmp_ans, 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()))

SA, SB = [0], [0]

for i in range(n):
    SA.append(SA[-1] + A[i])
for i in range(m):
    SB.append(SB[-1] + B[i])

res = bisect_right(SA, k) - 1


for i, sa in enumerate(SA):
    if k - sa > 0:
        tmp = i + bisect_right(SB, k - sa) - 1
        res = max(res, tmp)
    else:
        break
print(res)

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

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

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

    sum_A = [0]
    sum_B = [0]

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

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

    

    
    
    
    
    
    
    
    
    

    
    

    r = 0
    j = m

    for i in range(n + 1):
        a = sum_A[i]
        if a > k:
            break

        while j > -1:
            if sum_B[j] > k - a:
                j -= 1
            else:
                r = max(r, i + j)
                break

    print(r)
        

        
        
        
        
        
        
        
        
        

        
        
        
        
        

    


if __name__ == '__main__':
    main()

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

    sum_A = [A[0]]
    sum_B = [B[0]]

    for i in range(n - 1):
        sum_A.append(sum_A[i] + A[i + 1])

    for i in range(m - 1):
        sum_B.append(sum_B[i] + B[i + 1])

    R = []

    b = m - 1
    flag = False
    while b > -1:
        if sum_B[b] <= k:
            R.append(b + 1)
            flag = True
            break
        else:
            b -= 1

    if not flag:
        R.append(0)

    for i in range(n):
        a = sum_A[i]

        flag = False
        while b > -1:
            if sum_B[b] <= k - a:
                R.append(i + 1 + b + 1)
                flag = True
                break
            else:
                b -= 1

        if not flag:
            if 0 <= k - a:
                R.append(i + 1)
            else:
                R.append(0)

    print(max(R))
    
    
    
    
    
    
    

    
    

    
    
    

    
    
    
    
    
    
    
    
    

    


if __name__ == '__main__':
    main()

Solution (Python):
import bisect

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

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

acA = [0]
for i in range(n):
  acA.append(acA[i] + A[i])

acB = [0]
for i in range(m):
  acB.append(acB[i] + B[i])

ans = 0
for a in range(n+1):
  if k-acA[a] < 0: break
  b = bisect.bisect(acB, k-acA[a]) - 1
  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 = 0

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

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 itertools
def main():
    n,m,k=map(int, input().split())
    a=[int(i) for i in input().split()]
    b=[int(i) for i in input().split()]
    a = [0]+list(itertools.accumulate(a))
    b = [0]+list(itertools.accumulate(b))
    res = 0
    j = m
    best=0
    i=0

    while(i<n+1):
        if(a[i]>k):
            break
        while(b[j]+a[i]>k):
            j-=1
        res = max(res,i+j)
        i+=1
    print(res)



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_sum = [0]
for i in range(len(a)):
    a_sum.append(a_sum[len(a_sum)-1]+a[i])

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

ans = 0
b_i = len(b_sum)-1

for i in range(len(a_sum)):
    if a_sum[i] > k:
        break
    else:
        if b_i > -1:
            while b_sum[b_i] + a_sum[i] > k and b_i > -1:
                b_i -= 1
            if b_i > -1 and ans < i+b_i:
                ans = i+b_i
        else:
            if a_i > ans:
                ans = a_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 = [0]
b = [0]
for i in range(N):
  a.append(a[i]+A[i])
for i in range(M):
  b.append(b[i]+B[i])

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

Solution (Python):
from sys import stdin
import bisect

def main():
    input = stdin.readline
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = [0] * (n + 1)
    for i in range(n):
        c[i + 1] = c[i] + a[i]
    d = [0] * (m + 1)
    for i in range(m):
        d[i + 1] = d[i] + b[i]
    cnt = 0
    for i in range(n + 1):
        if c[i] > k:
            break
        e = bisect.bisect_right(d, k - c[i])
        if cnt < i + e - 1:
            cnt = i + e - 1
    print(cnt)
main()

Solution (Python):
import itertools
def main():
    n,m,k=map(int, input().split())
    a=[int(i) for i in input().split()]
    b=[int(i) for i in input().split()]
    a = [0]+list(itertools.accumulate(a))
    b = [0]+list(itertools.accumulate(b))
    res = 0
    j = m
    best=0
    for i in range(n+1):
        if(a[i]>k):
            break
        while(b[j] > k-a[i]):
            j-=1
        res = max(res,i+j)
    print(res)


if __name__ == '__main__':
    main()

Solution (Python):


import sys
stdin = sys.stdin
from itertools import accumulate
from bisect import bisect_left, bisect_right

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n, m, k = na()
    a = na()
    b = na()
    acum = list(accumulate(a))
    bcum = list(accumulate(b))
    i1, i2 = bisect_right(acum, k), 0
    ans = i1
    ssum = sum(a[:i1])
    
    while i1 > -1:
        if i2 != m:
            while ssum + b[i2] <= k:
                ssum += b[i2]
                i2 += 1
                if i2 == m:
                    break
        ans = max(ans, i1+i2)
        
        ssum -= a[i1-1]
        i1 -= 1
        
    print(ans)



if __name__ == "__main__":
    main()

Solution (Python):
from sys import stdin
import bisect

def main():
    input = stdin.readline
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = [0] * (n + 1)
    for i in range(n):
        c[i + 1] = c[i] + a[i]
    d = [0] * (m + 1)
    for i in range(m):
        d[i + 1] = d[i] + b[i]
    cnt = 0
    for i in range(n + 1):
        if c[i] > k:
            break
        e = bisect.bisect_right(d, k - c[i])
        if e > m and cnt < i + m:
            cnt = i + m
        if e <= m and cnt < i + e - 1:
            cnt = i + e - 1
    print(cnt)
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])
totaltime = 0
count,j = 0, M
 
for i in range(N+1):
    if a[i] > K:
        break
    while a[i] + b[j] > K:
        j -= 1
    count = max(count,i + j)
 
print(count)

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

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

Solution (Python):
from collections import deque
import numpy as np
import bisect

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

a = np.cumsum(A)
b = np.cumsum(B)

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

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
maxtemp = 0
bj = m
bsum = sum(b)
for i in range(n):
    if(asum >k):
        temp = i-1
        if(maxtemp < temp):
            maxtemp = temp
        break
    for j in range(bj):
        if(asum + bsum <= k):
            bj = bj - j
            temp = i + bj
            break
        bsum -= b[bj-1 - j]
    else:
        bj = 0
        temp = i
    if(maxtemp < temp):
        maxtemp = temp
    asum +=a[i]
for j in range(bj):
    if(asum + bsum <= k):
        bj = bj - j
        temp = n + bj
        break
    bsum -= b[bj-1 - j]
else:
    if(asum <= k):
        temp = n
if(maxtemp < temp):
    maxtemp = temp
print(maxtemp)

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()))
INF = 10 ** 18

acc_a = [0] + list(accumulate(a))
acc_b = [0] + list(accumulate(b))
j = m
ans = 0
for i, e in enumerate(acc_a):
    while j >= 0 and acc_b[j] > k - acc_a[i]:
        j -= 1

    if j == -1:
        break

    ans = max(ans, i + j)

print(ans)

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

N,M,K=list(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))

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

Solution (Python):
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,M,K = map(int, readline().split())
AB = np.array(read().split(), np.int64)

A = AB[:N]
B = AB[N:]

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

Acum = Acum[Acum <= K]
Bcum = Bcum[Bcum <= K]

x = np.searchsorted(Acum, K - Bcum, side='right') - 1
x += np.arange(len(Bcum))
print(x.max())

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

from itertools import accumulate
AS = [0] + list(accumulate(A))
BS = [0] + list(accumulate(B))

from bisect import bisect
ans = 0
for i in range(n+1):
    if AS[i] > k:
        break
    
    
    ans = max(ans, bisect(BS, k - AS[i])-1+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=[0]
B=[0]
ans=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 A[i]+B[j]>K:
    j-=1
  ans=max(ans,i+j)
print(ans)

Solution (Python):
import numpy as np
import sys
input = sys.stdin.buffer.readline

N, M, K = map(int, input().split())
cumA = np.zeros(N+1, dtype=np.int64)
cumA[1:] = np.array(input().split(), dtype=np.int64).cumsum()
cumB = np.zeros(M+1, dtype=np.int64)
cumB[1:] = np.array(input().split(), dtype=np.int64).cumsum()



cumA = cumA[cumA <= K]
cumB = cumB[cumB <= K]
ans = np.searchsorted(cumA, K - cumB, side='right') - 1
ans += np.arange(len(cumB))
print(ans.max())

Solution (Python):
import numpy as np
import sys
input = sys.stdin.buffer.readline

N, M, K = map(int, input().split())
cumA = np.zeros(N+1, dtype=np.int64)
cumA[1:] = np.array(input().split(), dtype=np.int64).cumsum()
cumB = np.zeros(M+1, dtype=np.int64)
cumB[1:] = np.array(input().split(), dtype=np.int64).cumsum()



ans = 0
for i in range(N, -1, -1):
    if cumA[i] > K: continue
    j = np.searchsorted(cumB, K-cumA[i], side='right')
    ans = max(ans, i+j-1)
print(ans)

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

import bisect
N, M, K = map(int, input().split())
A = list(map(int, (input().split())))
B = list(map(int, (input().split())))
cumA, cumB = [0], [0]
for a in A:
    cumA.append(cumA[-1]+a)
for b in B:
    cumB.append(cumB[-1]+b)
ans = 0
for i in range(N, -1, -1):
    if cumA[i] > K: continue
    j = bisect.bisect_right(cumB, K-cumA[i])
    ans = max(ans, i+j-1)
print(ans)

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

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

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

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

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

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

Solution (Python):

from itertools import accumulate
import sys
def main(N, M, K, A, B):
    *AA, = accumulate(A, initial=0)
    *BB, = accumulate(B, initial=0)

    def f(c):
        res = 10 ** 18
        for a in range(max(0, c - M), min(c, N) + 1):
            res = min(res, AA[a] + BB[c - a])
        return res

    l = 0
    r = N + M + 1
    while r - l > 1:
        m = (l + r) // 2
        if f(m) > K:
            r = m
        else:
            l = m
    print(l)

if __name__ == '__main__':
    input = sys.stdin.readline
    N, M, K = map(int, input().split())
    *A, = map(int, input().split())
    *B, = map(int, input().split())
    main(N, M, K, A, B)

Solution (Python):
import sys

def resolve():
    lines = sys.stdin.readlines()

    n, m, k = tuple(map(int, lines[0].strip().split(' ')))
    A = list(map(int, lines[1].strip().split(' ')))
    B = list(map(int, lines[2].strip().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])

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

resolve()

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

Solution (Python):

import sys
sys.setrecursionlimit(10**8)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))


INF = float("inf")
MOD = 10**9 + 7


def main():
    from bisect import bisect_right
    from itertools import accumulate
    N, M, K = MAP()
    A = LIST()
    B = LIST()

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

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


if __name__ == '__main__':
    main()

Solution (Python):
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = [0]
b = [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])
x = 0
bj = M
for i in range(N + 1):
    if a[i] > K:
        break
    for j in range(bj, -1, -1):
        if a[i] + b[j] <= K:
            bj = j
            x = max(x, i + j)
            break
print(x)

Solution (Python):
n, m, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))
for i in range(1, n + 1):
    a[i] += a[i - 1]
for i in range(1, m + 1):
    b[i] += b[i - 1]

ans = 0
for i in range(len(a)):
    rest = k - a[i]
    if rest < 0:
        break
    left, right = -1, len(b)
    while right - left > 1:
        mid = (left + right) // 2
        if rest - b[mid] >= 0:
            left = mid
        else:
            right = mid
    
    ans = max(ans, i + left)
print(ans)

Solution (Python):
from numpy import*
n,m,k,*a=int_(open(0).read().split())
c=cumsum
b=c([0]+a[:n])
print(max(range(len(b:=b[b<=k]))+searchsorted(c(a[n:]),k-b+1)))

Solution (Python):
def main():
    n, m, k = [int(e) for e in input().split()]
    A = [int(e) for e in input().split()]
    B = [int(e) for e in input().split()]

    AS = [0]
    for i in range(n):
        AS.append(AS[i] + A[i])

    BS = [0]
    for i in range(m):
        BS.append(BS[i] + B[i])

    ans = 0
    bi = 0
    for ai in range(n, -1, -1):
        if bi == m + 1:
            break

        if AS[ai] > k:
            continue

        while bi < m + 1 and AS[ai] + BS[bi] <= k:
            bi += 1

        ans = max(ai + bi - 1, ans)

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from numpy import*
n,m,k,*a=int_(open(0).read().split())
c=cumsum
b=c([0]+a[:n])
print(max(range(len(b:=b[b<=k]))+searchsorted(c(a[n:]),k-b,'r')))

Solution (Python):
from bisect import*;from itertools import*;n,_,k,*x=map(int,open(0).read().split());c=accumulate;*b,=c(x[n:]);print(max(i+bisect(b,k-v)for i,v in enumerate(c([0]+x[:n]))if v<=k))

Solution (Python):
from bisect import*
from itertools import*
n,_,k,*x=map(int,open(0).read().split());c=accumulate;*b,=c(x[n:]);print(max(i+bisect(b,k-v)for i,v in enumerate(c([0]+x[:n]))if v<=k))

Solution (Python):
from bisect import*
from itertools import*
n,_,k,*x=map(int,open(0).read().split());c=accumulate;*b,=c(x[n:]);print(max(i+bisect(b,k-v)for i,v in enumerate(c([0]+x[:n]))if v<=k))

Solution (Python):
from numpy import*
n,m,k,*a=int_(open(0).read().split())
c=cumsum
b=c(a[n:])
a=c([0]+a[:n])
print(max(range(len(a:=a[a<=k]))+searchsorted(b,k-a,'r')))

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()]
SA=[0 for i in range(N+1)]
SB=[0 for i in range(M+1)]
for i in range(N):
    SA[i+1]=A[i]+SA[i]
for i in range(M):
    SB[i+1]=B[i]+SB[i]
ans=0
for i in range(N+1):
    if SA[i]>K:
        break
    low=0
    high=M+1
    while(high-low>1):
        mid=(low+high)//2
        
        if SA[i]+SB[mid]<=K:
            low=mid
        else:
            high=mid
    ans=max(ans,i+low)
print(ans)

Solution (Python):
n,m,k,*x=map(int,open(0).read().split())
s=sum(x[:n])
z=i=j=n
x+=k,
while~i:
	while s+x[j]<=k:s+=x[j];j+=1
	if s<=k:z=max(z,i+j)
	i-=1
	s-=x[i]
print(z-n)

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
	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] + A
A = list(accumulate(A))

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

ans = 0
b_cnt = m
for a_cnt in range(n+1):
    if A[a_cnt] > k: continue

    while A[a_cnt]+B[b_cnt] > k:
        b_cnt -= 1
    ans = max(ans, a_cnt+b_cnt)

print(ans)

Solution (Python):
n,m,k,*x=map(int,open(0).read().split())
s=sum(x[:n])
z=i=j=n
while~i:
	while j<n+m and s+x[j]<=k:s+=x[j];j+=1
	if s<=k:z=max(z,i+j)
	i-=1
	s-=x[i]
print(z-n)

Solution (Python):
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import reduce
import math
import itertools
import heapq

import bisect
import sys

sys.setrecursionlimit(10**6)


def bfs(s, n, node):
    
    check = [False for _ in range(n)]
    check[s] = True
    
    queue = deque([s])
    visited_num = 1

    
    
    color = [-1 for _ in range(n)]
    color[s] = 0

    while visited_num < n:
        
        if len(queue) == 0:
            
            
            return color

        now_vertex = queue.popleft()
        
        for next_vertex in node[now_vertex]:

            if check[next_vertex] == True:
                continue

            queue.append(next_vertex)
            check[next_vertex] = True

            
            color[next_vertex] = color[now_vertex]+1
            visited_num += 1

    return color


mod = 10**9+7



def ceil(x, y): return (x+y-1)//y
def input_list(): return list(map(int, input().split()))


n, m, k = list(map(int, input().split()))
t_a = list(map(int, input().split()))
t_b = list(map(int, input().split()))

a = [0]
for each in t_a:
    a.append(each+a[-1])


b = [0]
for each in t_b:
    b.append(each+b[-1])

a_ind = bisect.bisect_right(a, k)


ans = 0
for i in range(a_ind):
    zan = k-a[i]
    b_ind = bisect.bisect_right(b, zan)-1
    cal = (i+b_ind)
    ans = max(ans, cal)
    

print(ans)

Solution (Python):

from bisect import bisect
from itertools import accumulate


def main():
    N, M, K, *AB = map(int, open(0).read().split())
    cum_A, cum_B = accumulate(AB[:N], initial=0), tuple(accumulate(AB[N:]))
    print(max(i + bisect(cum_B, K - a) for i, a in enumerate(cum_A) if a <= K))


if __name__ == "__main__":
    main()

Solution (Python):

from bisect import bisect
from itertools import accumulate


def main():
    N, M, K, *AB = map(int, open(0).read().split())
    cum_A, cum_B = accumulate(AB[:N], initial=0), tuple(accumulate(AB[N:]))
    candidates = [0]
    for i, a in enumerate(cum_A):
        if a > K:
            break
        candidates.append(i + bisect(cum_B, K - a))
    print(max(candidates))


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

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

print(ans)

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

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

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

print(ans)

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

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

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

print(ans)

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

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

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

print(ans)

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

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

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