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.



Sample input:
3 4 240
60 90 120
80 150 80 150


Sample output:
3

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
import numpy as numpy 
import bisect as bisect
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
a.insert(0,0)
ali = numpy.cumsum(a)
bli = numpy.cumsum(list(map(int,input().split())))
a = [0]
for i in range(n+1):
    if ali[i] > k:
        break
    b = bisect.bisect_right(bli,k-ali[i])
    a.append(i+b)
print(max(a))

Submission status: Accepted

Solution code:
import sys
from functools import reduce

def main(n, m, k, a, b):
    """ main
    """

    bestScore = 0
    _k = 0
    _ai = 0

    while True:
        if _ai >= n or _k + a[_ai] > k:
            bestScore = _ai
            break
        else:
            _k = _k + a[_ai]
            _ai = _ai + 1

    _bi = 0

    while _bi < m:
        _k = _k + b[_bi]

        while _k > k and _ai - 1 >= 0:
            _k = _k - a[_ai - 1] 
            _ai = _ai - 1

        if _k > k:
            break

        _bi = _bi + 1

        if _ai + _bi > bestScore:
            bestScore = _ai + _bi

    return bestScore

if __name__ == "__main__":
    N, M, K = map(int, sys.stdin.readline().split(" "))
    A = list(map(int, sys.stdin.readline().split(" ")))
    B = list(map(int, sys.stdin.readline().split(" ")))

    print(main(N, M, K, A, B))

Submission status: Accepted

Solution code:
n,m,k = map(int, input().split())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))

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

Submission status: Accepted

Solution code:
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()))
res = 0
a, b = [0], [0]

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

j = m

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

print(res)

Submission status: Accepted

Solution code:
n,m,k=map(int, input().split())
*a,=map(int, input().split())
*b,=map(int, input().split())
a=[0]+a
b=[0]+b
import numpy as np
a=np.cumsum(a)
b=np.cumsum(b)
bi=m
ans=0
for i in range(n+1):
    asm=a[i]
    while a[i]+b[bi]>k and bi:
        bi-=1
    if a[i]+b[bi]<=k:
        ans=max(ans,i+bi)
print(ans)

Submission status: Accepted

Solution code:
import bisect

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

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

# A,Bの累積和を取る
sumA = [0]*(n+1)
sumB = [0]*(m+1)
for i in range(n):
    sumA[i+1] = sumA[i] + A[i]
for i in range(m):
    sumB[i+1] = sumB[i] + B[i]


ans = 0
# 二分探索
for i,a in enumerate(sumA):
    if a > k:break
    j = bisect.bisect_right(sumB,k-a)
    ans = max(i + j - 1, ans)
print(ans)

Submission status: Accepted

Solution code:
import itertools
import bisect
N, M, K = map(int,input().split())
al = list(map(int,input().split()))
bl = list(map(int,input().split()))

als = list(itertools.accumulate(al))
als.insert(0,0)
bls = list(itertools.accumulate(bl))
bls.insert(0,0)
# print(als)
# print(bls)

ans = 0
for i in range(N+1):
    nokori = K - als[i]
    if nokori >= 0:
        index = bisect.bisect_right(bls,nokori)
        if index > 0:
            index -= 1
        tmp = i + index
        #print(i,index)
        if tmp > ans:
            ans = tmp
print(ans)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
n,m,k=map(int,input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
A=[0]
B=[0]
p=0
q=0
ans=0

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

import bisect
for i in range (n+1):
  if A[i]<=k:
    index = bisect.bisect_right(B, k-A[i])
    ans = max(ans, index+i-1)
    
  if A[i]>k:
    break
 
print(ans)

Submission status: Accepted

Solution code:
import bisect
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a_sum=[]
b_sum=[]
a_sum.append(0)
b_sum.append(0)
for i in range(n):
    a_sum.append(a_sum[i]+a[i])
for j in range(m):
    b_sum.append(b_sum[j]+b[j])
ans=0
for x in range(n+1):
    timecount=k-a_sum[x]
    if timecount>=0:
        y=bisect.bisect_right(b_sum,k-a_sum[x])-1
        ans=max(x+y,ans)
    else:
        break
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
from bisect import bisect_right

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

ac = np.cumsum(a)
bc = np.cumsum(b)
ans = 0

# print(ac)
# print(bc)

for i in range(n+1):
    if k < ac[i]:
        break
    time = k - ac[i]
    j = bisect_right(bc, time)
    ans = max(ans, j + i)

print(ans)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
def solve():
    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)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
import math

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())
rlf = lambda: map(float, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

def main():
	n, m, k = rli()
	A = deque(rli())
	B = deque(rli())
	L = deque()
	p, q = 0, 0
	currsum = 0
	for i, a in enumerate(A):
		if currsum + a <= k:
			currsum += a
			p += 1
		else:
			break
	cnt = p 
	for np in range(p, -1, -1):
		for i in range(q, len(B)):
			add = B[i]
			if add + currsum <= k:
				currsum += add
				q += 1
			else:
				break
		# print(f"At p, q = {np, q}, currsum = {currsum}")
		currsum -= A[np-1] if np > 0 else 0
		cnt = max(cnt, np + q)
	print(cnt)
	stdout.close()

if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate
from bisect import bisect_right, bisect_left

def solve():
    N, M, K = MI()
    A = LI()
    B = LI()
    A = [0] + list(accumulate(A))
    B = [0] + list(accumulate(B))

    ans = 0
    for i, a in enumerate(A):
        if a > K:
            break
        idx = bisect_right(B, K - a) - 1
        ans = max(ans, i + idx)
    print(ans)

        



if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate
from bisect import bisect_right, bisect_left

def solve():
    N, M, K = MI()
    A = LI()
    B = LI()
    A = [0] + list(accumulate(A))
    B = [0] + list(accumulate(B))

    def is_ok(arg, a):
        # b <= K - a
        # print(arg, B[arg], a, K, B[arg] <= K - a)
        return B[arg] <= K - a

    def meguru_bisect(ng, ok, a):
        while (abs(ok - ng) > 1):
            mid = (ok + ng) // 2
            if is_ok(mid, a):
                ok = mid
            else:
                ng = mid
            # print(ok, ng)
        return ok

    # print(A)
    # print(B)
    ans = 0
    for i, a in enumerate(A):
        idx = meguru_bisect(M+1, -1, a)
        if 0 <= idx <= M:
            ans = max(ans, i + idx)
    print(ans)

        



if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
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 = [0] + list(accumulate(A))
b = [0] + list(accumulate(B))

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)

Submission status: Accepted

Solution code:
a,b,k = map(int,input().split(" "))
r = list(map(int,input().split(" ")))
l = list(map(int,input().split(" ")))
ar = [0]
br = [0]
for i in range(a):
    ar.append(ar[-1] + r[i])
for i in range(b):
    br.append(br[-1] + l[i])
ans = 0
j = b
for i in range(len(ar)):
    if ar[i] > k:
        break
    while True:
        if ar[i] + br[j] <= k:
            t = i + j
            break
        j -= 1
    ans = max(ans,t)
print(ans)

Submission status: Accepted

Solution code:
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 = [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]
ans = 0
for i in range(n+1):
    cnt_a = i
    rest = k - sa[i]
    if rest < 0:
        break
    cnt_b = bisect_right(sb, rest) - 1
    ans = max(ans, cnt_a+cnt_b)
print(ans)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
import bisect

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

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

cum_b = [0]
for i in range(m):
    cum_b.append(cum_b[i] + b[i])

ans = 0
val = m
for i in range(n + 1):
    if cum_a[i] > k:
        break

    val = bisect.bisect_right(cum_b, k - cum_a[i]) - 1

    # while cum_b[val] > k - cum_a[i]:
    #    val -= 1

    ans = max(ans, i + val)

print(ans)

Submission status: Accepted

Solution code:
import itertools

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

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

count = 0
j = 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)

Submission status: Accepted

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a.insert(0,0)
b.insert(0,0)
j=1
while j<=m and b[j]+b[j-1]<=k:
  b[j]+=b[j-1]
  j+=1
  

j-=1
books=j
#print(books,b)

i=1
while i<n+1:
  a[i]+=a[i-1]
  while j>=0 and a[i]+b[j]>k:
    j-=1
  if(j!=-1) and a[i]+b[j]<=k:
    books=max(books,j+i)
    
    
    i+=1
    #print(books,b[:j+1],a[:i])
  else:
    break
print(books)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
cnt=0
a=0
b=0

while a<n and cnt<k:
    if cnt+A[a]<=k:
        cnt+=A[a]
        a+=1
    else:
        break
ans=a      
        
while b<m:
    if cnt+B[b]<=k:
        cnt+=B[b]
        b+=1
        ans=max(a+b,ans)
    elif a>0:
        a-=1
        cnt-=A[a]
    else:
        break
        
print(ans)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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 j in range(1, M+1):
    b[j] = b[j-1] + B[j-1]

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

Submission status: Accepted

Solution code:
import sys

INF = 10**9 + 5

N, M, K = map(int, sys.stdin.readline().rstrip().split())
A = [int(x) for x in sys.stdin.readline().rstrip().split()]
B = [int(x) for x in sys.stdin.readline().rstrip().split()]

tmpA = [INF] * (N + 1)
tmpA[0] = 0

cntA = 0
# A だけを読み続けた場合の所要時間を記録
for i in range(1, N + 1):
    tmpA[i] = A[i - 1] + tmpA[i - 1]
    cntA = i
    if tmpA[i] > K:
        break

# print(tmpA, cntA)  # cntA 冊目まで読める

# A を一冊ずつ減らして、最大値を探索
j = 0
vol = 0
tmpB = 0

for i in range(cntA, -1, -1):
    rest = K - tmpA[i]  # 残り時間
    # print(f"A{i} 残時間 : {rest}")
    while j < M + 1:
        # print(f"B {j}冊 {tmpB}分")
        if rest < tmpB:  # 　tmpB が残り時間を超えたら終了
            break
        vol = max(i + j, vol)
        if j >= M:
            break
        tmpB += B[j]  # 超えていなければ新しい本を追加してみる
        j += 1

print(vol)

Submission status: Accepted

Solution code:
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import math
sys.setrecursionlimit(4100000)
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))
input=lambda :sys.stdin.readline().rstrip()

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

suma=0
sumB=sum(B)
b=M-1

while K<sumB and b>=0:
    sumB-=B[b]
    b-=1
c=b+1
#print(c)
for a in range(N):
    sumB+=A[a]
    while K<sumB and b>=0:
        sumB-=B[b]
        b-=1
    #print(sumB,a,b,c)
    if K>=sumB:
        c=max(c,b+1+a+1)
print(c)

Submission status: Accepted

Solution code:
def bins(a, x):
    l = -1
    h = len(a)
    while (h-l) > 1:
        m = (l+h)//2
        if x >= a[m]:
            l = m
        else:
            h = m
    return l
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
pa, pb = [0] * (n+1), [0] * (m+1)
for i in range(n):
    pa[i+1] = pa[i] + a[i]
for i in range(m):
    pb[i+1] = pb[i] + b[i]
m = 0
for i in range(len(pa)):
    if pa[i] > k:
        break
    v = k - pa[i]
    bv = bins(pb, v)
    m = max(m, bv+i)
        
print(m)

Submission status: Accepted

Solution code:
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
pa, pb = [0] * (n+1), [0] * (m+1)
for i in range(n):
    pa[i+1] = pa[i] + a[i]
for i in range(m):
    pb[i+1] = pb[i] + b[i]
mx = 0
j = m
for i in range(n+1):
    if pa[i] > k:
        break
    v = k - pa[i]
    while pb[j] > v:
        j -= 1
    mx = max(mx, i+j)
print(mx)

Submission status: Accepted

Solution code:
FAST_IO = 1
if FAST_IO:
    import io, sys, atexit
    rr = iter(sys.stdin.read().splitlines()).next
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()
    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
    rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())
N,M, k= rrm()
a = rrm()
b = rrm()
prefix_a = [0]
for n in a:
    prefix_a.append(prefix_a[-1]+n)
prefix_b = [0]
for n in b:
    prefix_b.append(prefix_b[-1]+n)
ans = 0
b = M
for i in range(0, N+1):
    # take i from a
    while b>0 and (prefix_a[i] + prefix_b[b])>k :
        b -= 1
    if prefix_a[i]+prefix_b[b]<=k:
        ans = max(ans, i+b)
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

# C - Tsundoku

from itertools import accumulate, chain

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

def lister(a, b, k):
    """sequence of i+j while sum(a[:i]) + sum(b[:j]) <= k"""
    j = len(b)
    sumb = sum(b)
    for i, suma in enumerate(chain([0], accumulate(a))):
        if suma > k:
            break
        while suma + sumb > k and j > 0:
            j -= 1
            sumb -= b[j]
        if suma + sumb <= k:
            yield i + j

print(max(lister(a, b, k)))

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, M, K = LI()
    A = LI()
    B = LI()

    A_acc = [0] * (N + 1)
    for i in range(N):
        A_acc[i+1] = A_acc[i] + A[i]
    B_acc = [0] * (M + 1)
    for i in range(M):
        B_acc[i+1] = B_acc[i] + B[i]

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

    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

from itertools import accumulate
import bisect

sum_a_list = list(accumulate([0] + a_list))
sum_b_list = list(accumulate([0] + b_list))

ans = 0
b_idx = 0
for a_idx in range(n+1):
    if sum_a_list[a_idx] > k:
        continue

    time_rest = k - sum_a_list[a_idx]
    # 同じ数字を取った場合を考慮してleftでなくright
    b_idx = bisect.bisect_right(sum_b_list,time_rest) - 1
    
    ans = max(ans, a_idx + b_idx)
        
print(ans)

Submission status: Accepted

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

    t = 0
    for i in range(m):
        t += b[i]

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,m,k=map(int,input().split())
al=list(map(int,input().split()))
bl=list(map(int,input().split()))
a=[0]
b=[0]
for i in range(n):
    a.append(a[i]+al[i])
for i in range(m):
    b.append(b[i]+bl[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)

Submission status: Accepted

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

ma = [0] * (N + 1)
mb = [0]*(M+1)


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

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

j = M
max_num = 0

for i in range(N+1):
    if ma[i] > K:
        break
    while ma[i] + mb[j] > K:
        j -= 1
    max_num = max(max_num, i + j)
print(max_num)

Submission status: Accepted

Solution code:
import bisect
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a_acc = [0]
b_acc = [0]
now = 0
for i in range(n):
  now += a[i]
  a_acc.append(now)

now = 0
for i in range(m):
  now += b[i]
  b_acc.append(now)

ans = 0
for i in range(n+1):
  t = k - a_acc[i]
  if t < 0:
    break
  ind = bisect.bisect_left(b_acc, t)
  if ind == m+1:
    ans = max(ans, i+m)
    ind -= 1
  if b_acc[ind] == t:
    ans = max(ans, i+ind)
  else:
    ans = max(ans, i+ind-1)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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[-1]+A[i])
    
b_sum = [0]
for i in range(len(B)):
    b_sum.append(b_sum[-1]+B[i])

max_time = 0
b_idx = M
for i in range(len(a_sum)):
    if a_sum[i] > K:
        break
    for j in range(b_idx, -1, -1):
        if a_sum[i]+b_sum[j] <= K:
            max_time = max(max_time, i + j)
            b_idx = j
            break
print(max_time)

Submission status: Accepted

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

ans=0
for i in range(1,n+1):
  A[i]+=A[i-1]


for j in range(1,m+1):
  B[j]+=B[j-1]


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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
book_a = [0] * (n + 1)
book_b = [0] * (m + 1)

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

for j in range(m):
    book_b[j + 1] = book_b[j] + b[j]

r = m
ans = 0

for i in range(n + 1):
    if book_a[i] > k:
        break
    while book_a[i] + book_b[r] > k:
        r -= 1
    ans = max(ans, i + r)

print(ans)

Submission status: Accepted

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


def cumsum(l):
    s = 0
    for v in l:
        s += v
        yield s


a = [0] + list(cumsum(A))
b = [0] + list(cumsum(B))
ans = 0
n = N + 1
m = M
for i in range(n):
    if a[i] > K:
        continue
    for j in range(m, -1, -1):
        if a[i] + b[j] <= K:
            m = j
            break
        else:
            continue
    ans = max(ans, i + j)
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
from math import cos,sin,tan,sqrt
import cmath as cma
import copy as cp
import sys
import re
import bisect as bs
sys.setrecursionlimit(10**7)
EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf
MOD = 10**9 + 7

def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def adj(n): return [[] for _ in range(n)]

def meguru(ok, ng):
    while abs(ok - ng) > 1:
        mid = (ok + ng)//2
        if isOK(mid): ok = mid
        else: ng = mid
    return ok

def isOK(num): return bcum[num] <= tb

n,m,k = imap()
a,b = iarr(),iarr()
acum,bcum = np.array(a).cumsum(),np.array(b).cumsum()

anss = []
for i in range(n+1):
    ans = 0 if i==n else i + 1
    ta = 0 if i==n else acum[i]
    if ta > k: continue
    else: tb = k - ta
    ok,ng = -1,m
    ans += meguru(ok,ng) + 1 # OKなければansは-1+1で不変
    #ans += bs.bisect_right(bcum, tb)
    anss.append(ans)
ans = max(anss) if anss else 0
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
from math import cos,sin,tan,sqrt
import cmath as cma
import copy as cp
import sys
import re
import bisect as bs
sys.setrecursionlimit(10**7)
EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf
MOD = 10**9 + 7

def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def adj(n): return [[] for _ in range(n)]

def meguru(ok, ng):
    while abs(ok - ng) > 1:
        mid = (ok + ng)//2
        if isOK(mid): ok = mid
        else: ng = mid
    return ok

def isOK(num): return bcum[num] <= tb

n,m,k = imap()
a,b = iarr(),iarr()
acum,bcum = np.array(a).cumsum(),np.array(b).cumsum()

anss = []
for i in range(n+1):
    ans = 0 if i==n else i + 1
    ta = 0 if i==n else acum[i]
    if ta > k: continue
    else: tb = k - ta
    #ok,ng = -1,m
    #ans += meguru(ok,ng) + 1 # OKなければansは-1+1で不変
    ans += bs.bisect_right(bcum, tb)
    anss.append(ans)
ans = max(anss) if anss else 0
print(ans)

Submission status: Accepted

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

ans = 0

cnt = m

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