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: Runtime Error

Solution code:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
booka = 0
bookb = 0
booknum = 0
time = 0
ba=0
bb=0
lim = 0
while True:
    if booka >= N:
        while time<=K and bookb<M:
            bb += 1
            time += B[bookb]
            bookb += 1
        break
    if bookb>=M:
        while time<=K and booka<N:
            ba += 1
            time += A[booka]
            booka += 1
        break
    if A[booka]<B[bookb]:
        if A[booka]+A[booka+1] > B[bookb]+B[bookb+1]:
            time += B[bookb]
            bookb += 1
        else:
            time += A[booka]
            booka += 1
    else:
        if A[booka]+A[booka+1] <= B[bookb]+B[bookb+1]:
            time += A[booka]
            booka += 1
        else:
            time += B[bookb]
            bookb += 1
    if time >K:
        break
    booknum += 1
    while (booka == N-1 or bookb == M-1) and time <= K:
        if A[booka]<B[bookb]:
            time += A[booka]
            booka += 1
            if time > K:
                booknum += 1
        else:
            time += B[bookb]
            bookb += 1
            if time > K:
                booknum += 1
if time > K and (bb!=0 or ba!=0):
    booknum-=1
booknum += (ba+bb)

print(booknum)

Submission status: Runtime Error

Solution code:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
booka = 0
bookb = 0
booknum = 0
time = 0
ba=0
bb=0
lim = 0
while True:
    if booka >= N:
        while time<=K and bookb<M:
            bb += 1
            time += B[bookb]
            bookb += 1
        break
    if bookb>=M:
        while time<=K and booka<N:
            ba += 1
            time += A[booka]
            booka += 1
        break
    if A[booka]<B[bookb]:
        if A[booka]+A[booka+1] > B[bookb]+B[bookb+1]:
            time += B[bookb]
            bookb += 1
        else:
            time += A[booka]
            booka += 1
    else:
        if A[booka]+A[booka+1] <= B[bookb]+B[bookb+1]:
            time += A[booka]
            booka += 1
        else:
            time += B[bookb]
            bookb += 1
    if time >K:
        break
    booknum += 1
    while (booka == N-1 or bookb == M-1):
        if A[booka]<B[bookb]:
            time += A[booka]
            booka += 1
            if time > K:
                booknum += 1
        else:
            time += B[bookb]
            bookb += 1
            if time > K:
                booknum += 1
if time > K and (bb!=0 or ba!=0):
    booknum-=1
booknum += (ba+bb)

print(booknum)

Submission status: Runtime Error

Solution code:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
booka = 0
bookb = 0
booknum = 0
time = 0
ba=0
bb=0
lim = 0
while True:
    if booka >= N:
        while time<=K and bookb<M:
            bb += 1
            time += B[bookb]
            bookb += 1
        break
    if bookb>=M:
        while time<=K and booka<N:
            ba += 1
            time += A[booka]
            booka += 1
        break
    if A[booka]<B[bookb]:
        if A[booka]+A[booka+1] > B[bookb]+B[bookb+1]:
            time += B[bookb]
            bookb += 1
        else:
            time += A[booka]
            booka += 1
    else:
        if A[booka]+A[booka+1] <= B[bookb]+B[bookb+1]:
            time += A[booka]
            booka += 1
        else:
            time += B[bookb]
            bookb += 1
    if time >K:
        break
    booknum += 1
    while (booka == N-1 or bookb == M-1):
        if A[booka]<B[bookb]:
            time += A[booka]
            booka += 1
            if time > K:
                booknum += 1
            else:
                break
        else:
            time += B[bookb]
            bookb += 1
            if time > K:
                booknum += 1
            else:
                break
if time > K and (bb!=0 or ba!=0):
    booknum-=1
booknum += (ba+bb)

print(booknum)

Submission status: Runtime Error

Solution code:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
booka = 0
bookb = 0
booknum = 0
time = 0
ba=0
bb=0
lim = 0
while True:
    if booka >= N:
        while time<=K and bookb<M:
            bb += 1
            time += B[bookb]
            bookb += 1
        break
    if bookb>=M:
        while time<=K and booka<N:
            ba += 1
            time += A[booka]
            booka += 1
        break
    if A[booka]<B[bookb]:
        if A[booka]+A[booka+1] > B[bookb]+B[bookb+1]:
            time += B[bookb]
            bookb += 1
        else:
            time += A[booka]
            booka += 1
    else:
        if A[booka]+A[booka+1] <= B[bookb]+B[bookb+1]:
            time += A[booka]
            booka += 1
        else:
            time += B[bookb]
            bookb += 1
    if time >K:
        break
    booknum += 1
    while (booka == N-1 or bookb == M-1) and time <= K:
        if A[booka]<B[bookb]:
            time += A[booka]
            booka += 1
            booknum += 1
        else:
            time += B[bookb]
            bookb += 1
            booknum += 1
if time > K and (bb!=0 or ba!=0):
    booknum-=1
booknum += (ba+bb)

print(booknum)

Submission status: Runtime Error

Solution code:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
time=0
booka = 0
bookb = 0
booknum = 0
while True:
  if A[booka]<B[bookb]:
    time += A[booka]
    booka += 1
  else:
    time += B[bookb]
    bookb += 1
  if time>K:
    break
  booknum += 1
print(booknum)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon Sep  7 11:05:00 2020

@author: liang
"""

"""
片側を固定して、それぞれのケースに対して最適解を求める
それぞれのケースについて
index(b_i) =< index(b_i-1)
であるから、bの最大値bestを保存して探索することで重複探索を回避できる
"""
N, M, K = map(int, input().split())

A = [0] + [int(x) for x in input().split()]
B = [0] + [int(x) for x in input().split()]

s_b = 0
for i in range(M+1):
    s_b += B[i]
    if s_b > K:
        s_b -= B[i]
        best = i - 1
        break
res = best
#print(res)
s_a = 0
for i in range(N+1):
   # print("i", i)
    s_a += A[i]
    if s_a > K:
        break
    for j in reversed(range(best+1)):
        #print("j",j)
        if s_b <= K - s_a:
            if i + j > res:
                res = i + j
            best = j
            #print(i, j, s_a, s_b)
            break
        else:
            s_b -= B[j]

Submission status: Runtime Error

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

A_dp = [0] * (N + 1)
B_dp = [0] * (M + 1)

for i in range(1,N+1):
  if i == 1:
    A_dp[i] += A[i-1]
    continue
  A_dp[i] += A_dp[i-1] + A[i-1]
  
for j in range(1,M+1):
  if j == 1:
    B_dp[j] += B[j-1]
    continue
  B_dp[j] += B_dp[j-1] + B[j-1]
  
a = N
b = 0

minute = A_dp[a] + B_dp[b]
if K > minute:
  while K >= A_dp[a] + B_dp[b]:
    b += 1
else:
  while K < A_dp[a] + B_dp[b]:
    a -= 1
  
cnt = a + b
for k in range(a,-1,-1):
  while A_dp[k] + B_dp[b] < K:
    if b == M - 1:
      break
    b += 1
  b -= 1
  if cnt < k + b:
    cnt = k + b
    
print(cnt)

Submission status: Runtime Error

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

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

sumA=0
sumB=0
minAB=0

for i in range(n):
    sumA+=A[i]
for i in range(m):
    sumB+=B[i]
for i in range(min(n, m)):
    minAB+=A[i]+B[i]

if sumA+sumB<=k:
    ans=n+m
elif A[0]>k or B[0]>k:
    ans=0
else :
    if minAB>k:
        ans=min(n, m)
        if min(n, m)==n:
            for i in range(min(n, m), max(n, m)):
                if B[i]+minAB<k:
                    minAB+=B[i]
                    ans+=1
        else:
            for i in range(min(n, m), max(n, m)):
                if A[i]+minAB<k:
                    minAB+=B[i]
                    ans+=1
    else:
        for i in reversed(0, min(n,m)):
            if minAB-A[i]-B[i]>=k:
                minAB-=A[i]+B[i]
                ans-=2
            else:
                if minAB-A[i]<k or minAB-B[i]<k:
                    ans-=1
                else:
                    ans-=2
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N, M, K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
Asum = []
Bsum = []
a = 0
b = 0
for i in range(N):
    a += A[i]
    if a > K:
        break
    Asum.append(a)
for i in range(M):
    b += B[i]
    if b > K:
        break
    Bsum.append(b)
Asum.append(0)
Bsum.append(0)
res = 0
for i in range(-1,N):
    if Asum[i] > K:
        break
    for j in range(-1,M):
        if Asum[i] + Bsum[j] > K:
           break
        else:
           res = max(res,(i+j+2))
print(res)

Submission status: Runtime Error

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=0
d=0
e=0
ans=0
while c<k:
  if e<m and (a[d]>b[e] or (a[d]==b[e] and a[d+1]>=b[e+1])):
    c+=b[e]
    e+=1
    ans+=1
  elif d<n:
    c+=a[d]
    d+=1
    ans+=1
  else:
    break
if c==k:
  print(ans)
else:
  print(ans-1)

Submission status: Runtime Error

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=0
d=0
e=0
ans=0
while c<k:
  if c<n and (a[d]>b[e] or (a[d]==b[e] and a[d+1]>=b[e+1])):
    c+=b[e]
    e+=1
    ans+=1
  elif d<m:
    c+=a[d]
    d+=1
    ans+=1
  else:
    break
if c==k:
  print(ans)
else:
  print(ans-1)

Submission status: Runtime Error

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=0
d=0
e=0
ans=0
while c<=k:
  if c<n and (a[d]>b[e] or (a[d]==b[e] and a[d+1]>=b[e+1])):
    c+=b[e]
    e+=1
    ans+=1
  elif d<m:
    c+=a[d]
    d+=1
    ans+=1
  else:
    break
if c==k:
  print(ans)
else:
  print(ans-1)

Submission status: Runtime Error

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=0
d=0
e=0
ans=0
while c<=k:
  if a[d]>=b[e]:
    c+=b[e]
    e+=1
    ans+=1
  else:
    c+=a[d]
    d+=1
    ans+=1
if c==k:
  print(ans)
else:
  print(ans-1)

Submission status: Runtime Error

Solution code:
n,m,k=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=0
d=0
e=0
ans=0
while c<=k:
  if a[d]>=b[e]:
    c+=b[e]
    e+=1
    ans+=1
  else:
    c+=a[d]
    d+=1
    ans+=1
if c==k:
  print(ans)
else:
  print(ans-1)

Submission status: Runtime Error

Solution code:
n,m,k=int(input())
a=list(msp(int,input().split()))
b=list(msp(int,input().split()))
c=0
d=0
e=0
ans=0
while c<=k:
  if a[d]>=b[e]:
    c+=b[e]
    e+=1
    ans+=1
  else:
    c+=a[d]
    d+=1
    ans+=1
if c==k:
  print(ans)
else:
  print(ans-1)

Submission status: Runtime Error

Solution code:
n, m, k = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
aa = a.copy()
bb = b.copy()

aa = [sum(a[:s+1]) for s in range(n)]
bb = [sum(b[:s+1]) for s in range(m)]
      
temp, ans = 0, 0
j = m - 1

for i in range(n):
    if aa[i] > k:
        break
    while bb[j] > k - aa[i]:
        j -= 1
    temp = i+1 + j+1
    if temp > ans:
        ans = temp
        
print(ans)

Submission status: Runtime Error

Solution code:
n, m, k = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
aa = a.copy()
bb = b.copy()

aa = [sum(a[:s+1]) for s in range(n)]
bb = [sum(b[:s+1]) for s in range(m)]
      
temp, ans = 0, 0
j = m - 1

for i in range(n):
    if aa[i] > k:
        break
    while bb[j] > k - a[i]:
        j -= 1
    temp = i+1 + j+1
    if temp > ans:
        ans = temp
        
print(ans)

Submission status: Runtime Error

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

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

i = 0
a = 0
b = 0
time = 0
while True:
    i += 1
    if len(A) == 0:
        time += B[b]
        b += 1
    elif len(B) == 0:
        time += A[a]
        a += 1
    else:
        if A[a] <= B[b]:
            time += A[a]
            a += 1
        elif A[a] > B[b]:
            time += B[b]
            b += 1
    if K < time:
        print(i - 1)
        exit()
    elif len(A) == 0 and len(B) == 0:
        print(i)
        exit()

Submission status: Runtime Error

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

x = 0
for i in range(n):
    x += a[i]
    a[i] = x

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

x = 0
for i in range(n):
    x = a[i]
    if x > k:
        x = a[i-1]
        ans = i
        j = i-2
        break
    if i + 1 == n:
        ans = n
        j = i-1

y = 0
for i in range(m):
    y = b[i]
    if x + y > k:
        while x + y > k and j >= 0:
            x = b[j]
            j -= 1
    if x + y <= k:
        ans = max(ans,i+j+2)

print(ans)

Submission status: Runtime Error

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

x = 0
for i in range(n):
    x += a[i]
    a[i] = x

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

x = 0
for i in range(n):
    x = a[i]
    if x > k:
        x = a[i-1]
        ans = i
        j = i-1
        break
    if i + 1 == n:
        ans = n
        j = i

y = 0
for i in range(m):
    y = b[i]
    if x + y > k:
        while x + y > k and j != -1:
            x = b[j]
            j -= 1
    if x + y <= k:
        ans = max(ans,i+j+2)

print(ans)

Submission status: Runtime Error

Solution code:
n,m,k = map(int,input().split()) 
Al=list(map(int,input().split()) )
Bl=list(map(int,input().split()) )
bmax=0
A=[0]
B=[0]
for i in range(1,n+1):
    A[i] += A[i-1]+Al[i]  
for i in range(1,m+1):
    B[i] += B[i-1]+Bl[i]
    if B[i]<=k:
        bmax=i

ans=0
b=bmax
for a in range(len(A)):
    if A[a]>k:
        break
    # ans = max(ans, a+1)
    
    while A[a] + B[b] >k and b>=0:
        b -= 1
        
        
    ans = max(ans, a+b+2)
        
print(ans)

Submission status: Runtime Error

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

CON = 0

for i in range(n-1):
    for j in range(m-1):
        if a[i] >= b[j] :
            k -= b[j]
            if k >=0 :
                con += 1
            
        elif a[i] < b [j] :
            k -= a[i]
            if k >= 0:
                con += 1

print(con)

Submission status: Runtime Error

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

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

#リストが空になったときlen(a)=0 or len(b)=0
s=0
t=0
while len(a)>0 and len(b)>0:
    if a[0]>b[0]:
        s+=b[0]
        t+=1
        del b[0]
    elif a[0]<b[0]:
        s+=a[0]
        t+=1
        del a[0]
    elif a[0]==b[0]:
        if a[1]>=b[1]:
            s+=b[0]
            t+=1
            del b[0]
        else:
            s+=a[0]
            t+=1
            del a[0]
    if s>k:
        print(t-1)
        exit()

while len(a)>0 and len(b)==0:
    s+=a[0]
    t+=1
    del a[0]
    if s>k:
        print(t-1)
        exit()

while len(b)>0 and len(a)==0:
    s+=b[0]
    t+=1
    del b[0]
    if s>k:
        print(t-1)
        exit()    
        
print(t)


#リストがからのときの処理方法謎、sortさせて上から消すのが一番簡単、
#どこまでsortさせるのか
#sort

Submission status: Runtime Error

Solution code:
from itertools import accumulate
from bisect import bisect_right

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

for i in range(n + 1):
    c = bisect_right(b, k - a[i]) - 1
    print(c, b, k - a[i])
    if c != 1:
        ans.append(c + i)

print(max(ans))

Submission status: Runtime Error

Solution code:
import numpy as np

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

aa = [0]

for i in range(0, n):
  a1 = a[i]+aa[i-1]
  if a1 > k:
    break
  aa.append(a1)

del aa[0]
  
bb = [0]

for i in range(0, m):
  b1 = b[i]+bb[i-1]
  if b1 > k:
    break
  bb.append(b1)
  
del bb[0]
  
table = np.zeros((len(aa)+1, len(bb)+1))

table[1:, 0] = aa
table[0, 1:] = bb

for i in range(1, len(bb)+1):
  table[1:, i] = table[1:, i-1] + b[i-1]


table[(table>k)] = 0

maxindex = list(zip(*np.where(table==np.amax(table))))

ans = 0

for i in maxindex:
  f = i[0]+i[1]
  if f > ans:
    ans = f

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

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

aa = [a[0]]

for i in range(1, n):
  aa.append(a[i]+aa[i-1])
  
bb = [b[0]]

for i in range(1, m):
  bb.append(b[i]+bb[i-1])
  
table = np.zeros((n+1, m+1))

table[1:, 0] = aa
table[0, 1:] = bb

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

table[(table>k)] = 0

maxindex = list(zip(*np.where(table==np.amax(table))))

ans = 0

for i in maxindex:
  f = i[0]+i[1]
  if f > ans:
    ans = f

print(ans)

Submission status: Runtime Error

Solution code:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
t = sum(b)
ans = 0
j = m

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)

Submission status: Runtime Error

Solution code:
import sys
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
t = k
start = 0
while True:
  if start == len(b):
    break
  else:
    if t - b[start] < 0:
      break
    else:  
      t -= b[start]
      start += 1

num = start
lst = [0]
M = 0

for i in range(len(a)):
  while a[i] > t:
    b_ = b.pop()
    t = t+b_
    num -= 1
  t -= a[i]
  num += 1
  
 
  if lst[-1] < num:
    M = num
  lst.append(num)    
    
print(M)

Submission status: Runtime Error

Solution code:
import sys
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
t = k
start = 0
while True:
  if start == len(b):
    break
  else:
    if t - b[start] < 0:
      break
    else:  
      t -= b[start]
      start += 1

num = start
lst = [0]
M = 0
print(start,t)
for i in range(len(a)):
  while a[i] > t:
    b_ = b.pop()
    t = t+b_
    num -= 1
  t -= a[i]
  num += 1
  print(num,t)
 
  if lst[-1] < num:
    M = num
  lst.append(num)    
    
print(M)

Submission status: Runtime Error

Solution code:
import bisect
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(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]

I = bisect.bisect_right(a, k)
ans = bisect.bisect_right(b, k)
li = list(range(I))
li = li[::-1]
for i in li:
    tmp = bisect.bisect_right(b, k-a[i])
    if a[i] + b[tmp-1] <= k && tmp != 0:
        ans = max(ans, i+tmp+1)

print(ans)

Submission status: Runtime Error

Solution code:
def dfs(kazu,i,j,ans):
    global result
    if ans>k:
        result.append(kazu-1)
        return
    elif i==n and j==m:
        result.append(kazu)
        return
    elif i==n:
        #bの本を読む
        dfs(kazu+1,i,j+1,ans+b[j])
    elif j==m:
        #aの本を読む
        dfs(kazu+1,i+1,j,ans+a[i])
    else:
        #aの本を読む
        dfs(kazu+1,i+1,j,ans+a[i])
        #bの本を読む
        dfs(kazu+1,i,j+1,ans+b[j])

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

result = []

dfs(0,0,0,0)

print(max(result))

Submission status: Runtime Error

Solution code:
def dfs(kazu,i,j,ans):
    global result
    if ans>k:
        result.append(kazu-1)
        return
    elif i>=n and j>=m:
        result.append(kazu)
        return
    elif i>=n:
        #bの本を読む
        dfs(kazu+1,i,j+1,ans+b[j])
    elif j>=m:
        #aの本を読む
        dfs(kazu+1,i+1,j,ans+a[i])
    else:
        #aの本を読む
        dfs(kazu+1,i+1,j,ans+a[i])
        #bの本を読む
        dfs(kazu+1,i,j+1,ans+b[j])

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

result = []

dfs(0,0,0,0)

print(max(result))

Submission status: Runtime Error

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
index_a=0
index_b=0
tot=0
count=0
while index_a<len(a) or index_b<len(b):
	if index_a<len(a) and index_b<len(b):
		if a[index_a]<=b[index_b]:
			tot+=a[index_b]
			if tot>k:
				break
			count+=1
			index_a+=1
		else:
			tot+=b[index_b]
			if tot>k:
				break
			count+=1
			index_b+=1
	elif index_a>=len(a) and index_b<len(b):
		tot+=b[index_b]
		if tot>k:
			break
		count+=1
		index_b+=1
		
	elif index_a<len(a) and index_b>=len(b):
		tot+=a[index_a]
		if tot>k:
			break
		count+=1
		index_b+=1
	else:
		break
		
print(count)

Submission status: Runtime Error

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

def solve(a, b, k):
    if not a and not b:
        return 0
    if a and not b:
        if k >= a[0]:
            return 1 + solve(a[1:], b, k - a[0])
        return 0
    if not a and b:
        if k >= b[0]:
            return 1 + solve(a, b[1:], k - b[0])
        return 0

    if a[0] < b[0]:
        if k >= a[0]:
            return 1 + solve(a[1:], b, k - a[0])
        else:
            return 0
    if a[0] > b[0]:
        if k >= b[0]:
            return 1 + solve(a, b[1:], k - b[0])
        else:
            return 0
    else:
        if k >= a[0]:
            take_a = 1 + solve(a[1:], b, k - a[0])
            take_b = 1 + solve(b[1:], b, k - b[0])
            return max(take_a, take_b)
        else:
            return 0

ans = solve(a, b, k)
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

N, M, K = map(int, input().split())
A = np.array(input().split(), dtype=np.int64)
B = np.array(input().split(), dtype=np.int64)

# 累積和
A = np.cumsum(A)
B = np.cumsum(B)

# K以下を抽出
A = A[A <= K]
B = B[B <= K]

# Aを逆順にする
A = A[::-1]

c = 0
c_max = 0
for i, a in enumerate(A):
    c += len(A) - i

    for j, b in enumerate(B):
        if a + b <= K:
            cb = j + 1

    c += cb
    if c > c_max:
        c_max = c
    c = 0

print(c_max)

Submission status: Runtime Error

Solution code:
from collections import deque
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a_stack=deque([])
now=0
mn=0
j=0
for i in a:
  mn+=i
  if mn>k:
    mn-=i
    break
  else:
    now+=1
    a_stack.append(i)
for i in b:
  mn+=i
  if mn>k:
    mn-=i
    break
  else:
    now+=1
    j+=1
ans=now
while a_stack:
  if j>=m:
    break
  else:
    q=a_stack.pop()
    mn-=q
    now-=1
    while k-mn>0:
      mn+=b[j]
      now+=1
      j+=1
      if k-mn<0:
        now-=1
        mn-=b[j]
        j-=1
        break
      if j==m:
        break
    ans=max(now,ans)
print(ans)

Submission status: Runtime Error

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
  return int(readline())
n,m,k = readInts()
A = readInts()
B = readInts()
A = [0] + list(accumulate(A))
B = list(accumulate(B))
ans = 0
for i in range(len(A)):
    res = A[i]
    print('res:',A[i])
    print(B)
    r = bisect.bisect_right(B, k-res+1)
    print(r,'\n - - -\n')
    #print(i,r)
    if res <= k:
        ans = max(ans , i+r)
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

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

a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

a_cum = np.cumsum(a)
b_cum = np.cumsum(b)

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

Submission status: Runtime Error

Solution code:
N,M,K=map(int,input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
t=0
c=0
while 1:
  if t>=K:
    print(c)
    break
  elif K<A[0] and K<B[0]:
    print(c)
    break
  else:
    if len(A)==0:
      t=t+B[0]
      B.remove(B[0])
      c=c+1
    elif len(B)==0:
      t=t+A[0]
      A.remove(A[0])
      c=c+1
    else:
      if A[0]>=B[0]:
        t=t+A[0]
        A.remove(A[0])
        c=c+1
      else:
        t=t+B[0]
        B.remove(B[0])
        c=c+1

Submission status: Runtime Error

Solution code:
# ==================================================-
# 二分探索
# functionを満たす,search_listの最大の要素を出力
# 【注意点】searchリストの初めの方はfunctionを満たし、後ろに行くにつれて満たさなくなるべき
import math
import sys

sys.setrecursionlimit(10 ** 9)


def binary_research(start, end,function):
    if start == end:
        return start
    middle = math.ceil((start + end) / 2)
    if function(middle, k, a_sum, b_sum):
        start = middle
    else:
        end = middle - 1
    return binary_research(start, end, function)


# ==================================================-

n, m, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
a_sum = [0]
b_sum = [0]
for book in a:
    a_sum.append(a_sum[-1] + book)
for book in b:
    b_sum.append(b_sum[-1] + book)


def can_read(num, k, a_sum, b_sum):
    min_read_time = 1000000000000
    sentou=
    for i in range(max(0, num - m), min(num+1,n+1)):
        a_num = i
        b_num = num - i
        min_read_time = min(min_read_time, a_sum[a_num] + b_sum[b_num])
    if min_read_time <= k:
        return True
    return False


start = 0
end = n + m

print(binary_research(start, end, can_read))

Submission status: Runtime Error

Solution code:
# ==================================================-
# 二分探索
# functionを満たす,search_listの最大の要素を出力
# 【注意点】searchリストの初めの方はfunctionを満たし、後ろに行くにつれて満たさなくなるべき
import math
import sys

sys.setrecursionlimit(10 ** 9)


def binary_research(start, end,function):
    if start == end:
        return start
    middle = math.ceil((start + end) / 2)
    if function(middle, k, a_sum, b_sum):
        start = middle
    else:
        end = middle - 1
    return binary_research(start, end, function)


# ==================================================-

n, m, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
a_sum = [0]
b_sum = [0]
for book in a:
    a_sum.append(a_sum[-1] + book)
for book in b:
    b_sum.append(b_sum[-1] + book)


def can_read(num, k, a_sum, b_sum):
    min_read_time = 1000000000000
    for i in range(min(max(0, num - m),n), n + 1):
        a_num = i
        b_num = num - i
        min_read_time = min(min_read_time, a_sum[a_num] + b_sum[b_num])
    if min_read_time <= k:
        return True
    return False


start = 0
end = n + m

print(binary_research(start, end, can_read))

Submission status: Runtime Error

Solution code:
# ==================================================-
# 二分探索
# functionを満たす,search_listの最大の要素を出力
# 【注意点】searchリストの初めの方はfunctionを満たし、後ろに行くにつれて満たさなくなるべき
import math
import sys

sys.setrecursionlimit(10 ** 9)


def binary_research(start, end,function):
    if start == end:
        return start
    middle = math.ceil((start + end) / 2)
    if function(middle, k, a_sum, b_sum):
        start = middle
    else:
        end = middle - 1
    return binary_research(start, end, function)


# ==================================================-

n, m, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
a_sum = [0]
b_sum = [0]
for book in a:
    a_sum.append(a_sum[-1] + book)
for book in b:
    b_sum.append(b_sum[-1] + book)


def can_read(num, k, a_sum, b_sum):
    min_read_time = 1000000000000
    for i in range(max(0, num - m), n + 1):
        a_num = i
        b_num = num - i
        min_read_time = min(min_read_time, a_sum[a_num] + b_sum[b_num])
    if min_read_time <= k:
        return True
    return False


start = 0
end = n + m

print(binary_research(start, end, can_read))