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())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
As = list(reversed(As))
Bs = list(reversed(Bs))

count = 0
while 1:
    A = As[-1]
    B = Bs[-1]

    if A>K and B>K:
        break

    count+=1
    selected = None
    if A > B:
        selected = "B"
    elif B > A:
        selected = "A"
    else:
        current_arg = len(As)-2
        while 1:
            if current_arg < 0:
                selected = "A"
                break
            tmp_a = As[current_arg]
            tmp_b = Bs[current_arg]

            if tmp_a > tmp_b:
                selected = "B"
                break
            elif tmp_b > tmp_a:
                selected = "A"
                break
            else:
                current_arg-=1

    if selected == "A":
        selected = As.pop()
    else:
        selected = Bs.pop()
    K-=selected
    if len(As)==0:
        As = [1e10]
    if len(Bs)==0:
        Bs = [1e10]
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()))
x=[0]*n
y=[0]*m
x[0]=a[0]
y[0]=b[0]
for i in range(0,n-1):
    x[i+1]=x[i]+a[i+1]
for i in range(0,m-1):
    y[i+1]=y[i]+b[i+1]
ans,j=0,m
for i in range(n):
    if x[i]>k:
        break
    while y[j-1]>k-x[i]:
        j-=1
    ans=max(i+1+j,ans)
print(ans)

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

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

ans = 0
for i in range(N+1):
    if A[i] <= K:
        ans = max(ans, i + bisect.bisect_right(b, K - a[i])-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()))

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):
	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:
from collections import deque
n, m, k = [int(n) for n in input().split()]
A = deque([int(n) for n in input().split()])
B = deque([int(n) for n in input().split()])
dp = [0] * k

t, n = 0, 0
while True:
    a = A[0] if A else None
    b = B[0] if B else None
    if a and a < b:
        d = A.popleft()
    elif b:
        d = B.popleft()
    t += d
    if t > k:
        break
    n += 1
print(n)

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

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):
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:
from collections import deque
from bisect import bisect_left, bisect_right
from itertools import accumulate


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

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

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

print(ans)

Submission status: Runtime Error

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

count = 0
while 1:
    A = As[-1]
    B = Bs[-1]

    if A>K and B>K:
        break

    count+=1
    selected = None
    if A > B:
        selected = "B"
    elif B > A:
        selected = "A"
    else:
        current_arg = len(As)-2
        while 1:
            tmp_a = As[current_arg]
            tmp_b = Bs[current_arg]

            if tmp_a > tmp_b:
                selected = "B"
                break
            elif tmp_b > tmp_a:
                selected = "A"
                break
            else:
                current_arg-=1

    if selected == "A":
        selected = As.pop()
    else:
        selected = Bs.pop()
    K-=selected
    if len(As)==0:
        As = [1e10]
    if len(Bs)==0:
        Bs = [1e10]
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()))
a = [0]
b = [0]
for i in range(N):
  a.append(a[i] + A[i])
for i in range(M):
  b.append(b[i] + B[i])
  
ans = 0
j = M
for i in range(N+1):
  if a[i] > K:
    break
  while b[i] > 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()))
cum_A=[]
cum_B=[]
for i in range(N):
  cum_A.append(cum_A[-1]+A[i])
  cum_B.append(cum_B[-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:
import numpy as np

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

num_book = 0
dp = np.zeros((N + 2, M + 2)).astype(bool)

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

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

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

Submission status: Runtime Error

Solution code:

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

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

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

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

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

L = [float("inf") for _ in range(N+M+1)]
L[0] = 0

a = 0
b = 0
ans = 0
for k in range(len(A)):
    a += A[k]
    A[k] = a
for k in range(len(B)):
    b += B[k]
    B[k] = b

AA = [0] + A

BB = [0] + B

for k in range(N+1):
    for j in range(ans-k, M+1):
        if  K >= AA[k] + BB[j]:
            ans = max(k+j, ans)
            continue
        else:
            break
print(ans)

Submission status: Runtime Error

Solution code:
import sys
N, M, K = [int(x) for x in input().split()]
A = [float(x) for x in input().split()]
B = [float(x) for x in input().split()]
 
AB = list()
a = 0
b = 0
for i in range(N+M):
  if ((a < N) and (b < M)):
    if(A[a] == B[b]):
      AB.append(A[a])
      a += 1
      AB.append(B[b])
      b += 1
    elif(A[a] < B[b]):
      AB.append(A[a])
      a += 1
    else:
      AB.append(B[b])
      b += 1
  elif(a == N):
    for j in range(M-b):
      AB.append(B[b])
      b += 1
    break
  elif(b == M):
    for j in range(N-a):
      AB.append(A[a])
      a += 1
    break
    
ans = 0
K = float(K)
while K >= 0:
  K -= AB[ans]
  ans += 1
  if((ans == (N+M)) and (K > 0)):
    print(N+M)
    sys.exit()
  
print(ans-1)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

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

time = 0
A_num = 0
B_num = 0
A_len = len(A_list)
B_len = len(B_list)
while (time <= K) and (A_num != A_len or B_num != B_len):
    if A_num >= A_len:
        B = B_list[B_num]
        time += B
        B_num += 1

    elif B_num >= B_len:
        A = A_list[A_num]
        time += A
        A_num += 1
    else:
        A = A_list[A_num]
        B = B_list[B_num]
        if A < B:
            time += A
            A_num += 1

        elif A > B:
            time += B
            B_num += 1

        else:
            add = 1
            time += A
            while (A_list[A_num + add] == B_list[B_num + add]) and \
                  (time < K):
                time += A_list[A_num + add]
                add += 1
            if A_list[A_num + add] < B_list[B_num + add]:
                A_num += add
            else:
                B_num += add
print(A_num + B_num)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

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

time = 0
A_num = 0
B_num = 0
A_len = len(A_list)
B_len = len(B_list)
while (time <= K) and (A_num != A_len or B_num != B_len):
    if A_num >= A_len:
        B = B_list[B_num]
        time += B
        B_num += 1

    elif B_num >= B_len:
        A = A_list[A_num]
        time += A
        A_num += 1
    else:
        A = A_list[A_num]
        B = B_list[B_num]
        if A < B:
            time += A
            A_num += 1

        elif A > B:
            time += B
            B_num += 1

        else:
            add = 1
            time += A
            while (A_list[A_num + add] == B_list[B_num + add]) and \
                  (time < K):
                time += A_list[A_num + add]
                add += 1
            if A_list[A_num + add] < B_list[B_num + add]:
                A_num += add
            else:
                B_num += add
    print(time)
print(A_num + B_num)

Submission status: Runtime Error

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

import pandas as pd
nss = pd.Series([0] + ns).cumsum()
mss = pd.Series([0] + ms).cumsum()

mx = 0
for i in range(n + 1):
    if nss[i] > k:
        break

    j = -1
    for v in mss:
        if nss[i] + v > k:
            break
        j += 1
    mx = max(mx, i + j)

print(mx)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))


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

max_j = M
max_book = 0
for i in range(N+1):
    # Aの机でi冊読んだときのBの机で読む最大値
    if sum_A > K:
        break
    for j in range(max_j,-1,-1):
        if sum_A[i]+sum_B[j] <= K:
            max_j = j
            break
    else:
        max_j = 0
    
    max_book = max(max_book, i+max_j)

print(max_book)

Submission status: Runtime Error

Solution code:
from collections import deque
n, m, k = [int(n) for n in input().split()]
A = deque([int(n) for n in input().split()])
B = deque([int(n) for n in input().split()])
dp = [0] * k

t, n = 0, 0
while True:
    a = A[0] if A else None
    b = B[0] if B else None
    if a and a < b:
        d = A.popleft()
    elif b:
        d = B.popleft()
    t += d
    if t > k:
        break
    n += 1
print(n)

Submission status: Runtime Error

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

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

ans = 0
count = 0
j = 0
for i in range(0,N):
    if ans >= K-A[i]:
        break
    else:
        ans += A[i]
        count += 1

#print(ans)

for j in range(0,M):
    if ans >= K-B[i]:
        break
    else:
        ans += B[i]
        count += 1

#print(ans)
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()))
count = 0
ANS = 0

for i in range(len(A)):
    count += A[i]
    if (count > K) or (i==len(A)-1):
        del A[i+1:]
        count=0
        ANS += len(A)
        break

for i in range(len(B)):
    count += B[i]
    if (count > K) or (i==len(B)-1):
        del B[i+1:]
        count=0
        ANS += len(B)
        break

count = sum(A) + sum(B)




while count > K:
    if A[-1] > B[-1]:
        count -= A[-1]
        del A[-1]
        ANS -= 1
    else:
        count -= B[-1]
        del B[-1]
        ANS -= 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()))


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


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

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 = [sum(A[:i+1]) for i in range(len(A)) if sum(A[:i+1]) <= K]
B = [sum(B[:i+1]) for i in range(len(B)) if sum(B[:i+1]) <= K]

len_B = len(B)
res = []
for i, a in enumerate(A):
    for j in range(len_B)[::-1]:
        # print(i+1, j+1, a, B[j], a+B[j], K)
        if a + B[j] <= K:
            res.append(i+j+2)
            break
    len_B = j+1

print(max(res))

Submission status: Runtime Error

Solution code:
import numpy

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

li_A = numpy.cumsum(li_a)
li_B = numpy.cumsum(li_b)

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

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

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

ans = 0
for i in range(N+1):
    ans = max(ans, i + bisect.bisect_right(b, K - a[i]))

print(ans)

Submission status: Runtime Error

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

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

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

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

for i in range(len(A)):
    count += A[i]
    if (count > K) or (i==len(A)-1):
        del A[i+1:]
        count=0
        ANS += len(A)
        break

for i in range(len(B)):
    count += B[i]
    if (count > K) or (i==len(B)-1):
        del B[i+1:]
        count=0
        ANS += len(B)
        break
print(A, B, ANS)
count = sum(A) + sum(B)




while count > K:
    if A[-1] > B[-1]:
        count -= A[-1]
        del A[-1]
        ANS -= 1
    else:
        count -= B[-1]
        del B[-1]
        ANS -= 1

print(ANS)

Submission status: Runtime Error

Solution code:
/usr/bin/env python3
import sys


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

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

Submission status: Runtime Error

Solution code:
import numpy as np
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()))
A.insert(0, 0)
B.insert(0, 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])
num=0
for i in range(len(A_sum)):
    for l in range(len(B_sum)):
        if num<i+l:
            Time=A_sum[i]+B_sum[l]
            if Time<=K:
                num=i+l
print(num)

Submission status: Runtime Error

Solution code:
import numpy as np
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()))
A.insert(0, 0)
B.insert(0, 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])
num=0
if len(B)>=len(A):
    for i in range(len(A_sum)):
        for l in range(len(B_sum)):
            if num<i+l:
                Time=A_sum[i]+B_sum[l]
                if Time<=K:
                    num=i+l
else:
    for i in range(len(B_sum)):
        for l in range(len(A_sum)):
            if num<i+l:
                Time=A_sum[i]+B_sum[l]
                if Time<=K:
                    num=i+l 
print(num)

Submission status: Runtime Error

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


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

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

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

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

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

def Tundoku(a,b,count,k,K,N,M):
    if k > K :
        count -= 1
        return count
    else:
        if a == N-1 and b == M-1:
            k += min(A[a],B[b])
            if k > K:
                return count
            else:
                k += A[a] + B[b]
                if k > K:
                    count += 1
                    return count
                else:
                    count += 2
                    return count
        if a == N-1 and b != M-1:
            k += B[b]
            count += 1
            return Tundoku(a,b+1,count,k,K,N,M)
        elif a != N-1 and b == M-1:
            k += A[a]
            count += 1
            return Tundoku(a+1,b,count,k,K,N,M)
        else:
            if A[a] == B[b]:
                k += A[a]
                count += 1
                return max(Tundoku(a+1,b,count,k,K,N,M),Tundoku(a,b+1,count,k,K,N,M))

            elif A[a] > B[b] :
                k += B[b]
                count += 1
                return Tundoku(a,b+1,count,k,K,N,M)
            else:
                k += A[a]
                count += 1
                return Tundoku(a+1,b,count,k,K,N,M)

ans = Tundoku(0,0,0,0,K,N,M)

print(ans)

Submission status: Runtime Error

Solution code:
root = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))    
minute=0
books=0
ai=0
bi=0

while minute <= root[2]:
    if len(a) == ai:
        while minute <= root[2]:
            minute += b[bi]
            books += 1
            bi += 1
        break
    if len(b) == bi:
        while minute <= root[2]:
            minute += a[ai]
            books += 1
            ai += 1
        break
    if a[ai] < b[bi]:
        minute += a[ai]
        books += 1
        ai += 1
    elif b[bi] < a[ai]:
        minute += b[bi]
        books += 1
        bi += 1
    else:
        if len(a) == ai and len(b) == bi:
            books += 1
            break
        if len(a) > ai:
            minute += a[ai]
            books += 1
            ai += 1
        elif len(b) > bi:
            minute += b[bi]
            books += 1
            bi += 1
            
        
print(books-1)

Submission status: Runtime Error

Solution code:
import itertools
import decimal
import math
from collections import Counter
import sys
input = sys.stdin.readline

N,M,K=map(int,input().split())
dpA=[0]*N
dpB=[0]*M
ListA=list(map(int,input().split()))
ListB=list(map(int,input().split()))

dpA[0]=ListA[0]
for i in range(1,N):
    dpA[i]=dpA[i-1]+ListA[i]
dpB[0]=ListB[0]
for i in range(1,M):
    dpB[i]=dpB[i-1]+ListB[i]

total=0
if(dpA[1]>K and dpB[1]>K):
    Cnt=0
    
else:
    for i in range(N):
        for j in range(M):
            total=dpA[i]+dpB[j]
            Cnt=i+j+2
            if(total==K):
                break
            if(total>K):
                Cnt-=1
                break
                    
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()))

def Tundoku(a,b,count,k,K,N,M):
    if k > K :
        count -= 1
        return count
    else:
        if a == N-1 and b == M-1:
            k += min(A[a],B[b])
            if k > K:
                return count
            else:
                k += max(A[a],B[b])
                if k > K:
                    count += 1
                    return count
                else:
                    count += 2
                    return count
        if a == N-1 and b != M-1:
            k += B[b]
            count += 1
            return Tundoku(a,b+1,count,k,K,N,M)
        elif a != N-1 and b == M-1:
            k += A[a]
            count += 1
            return Tundoku(a+1,b,count,k,K,N,M)
        else:
            if A[a] == B[b]:
                k += A[a]
                count += 1
                return max(Tundoku(a+1,b,count,k,K,N,M),Tundoku(a,b+1,count,k,K,N,M))

            elif A[a] > B[b] :
                k += B[b]
                count += 1
                return Tundoku(a,b+1,count,k,K,N,M)
            else:
                k += A[a]
                count += 1
                return Tundoku(a+1,b,count,k,K,N,M)

ans = Tundoku(0,0,0,0,K,N,M)

print(ans)

Submission status: Runtime Error

Solution code:
from collections import deque
from sys import exit

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

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

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

search = deque()
check = {}


def search_count(v):
    search.appendleft(v)
    while search:
        v = search.popleft()

        if not v in check:
            check[v] = v[0] + v[1]

            if not (v[0] + 1, v[1]) in check:
                if v[0] + 1 <= N:
                    if a_book[v[0] + 1] + b_book[v[1]] <= K:
                        search.appendleft((v[0] + 1, v[1]))

            if not (v[0], v[1] + 1) in check:
                if v[1] + 1 <= M:
                    if a_book[v[0]] + b_book[v[1] + 1] <= K:
                        search.appendleft((v[0], v[1] + 1))


search_count((0, 0))

print(max(check.values()))

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

if k < a[i] or k < b[j]:
    k = -1

while k > time and i != n and j != m:
    if a[i] >= b[j] and k >= time:
        time += b[j]
        j += 1
        count += 1
        if j == m and i != n-1 and k >= time:
            while i != n:
                time += a[j]
                i += 1
                count += 1
    if a[i] <= b[j] and k >= time:
        time += a[i]
        i += 1
        count += 1
        if i == n and j != m-1 and k >= time:
            while j != m:
                time += b[j]
                j += 1
                count += 1

if count > 0 and k < time:
    count -= 1

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

count = 0
ar = [0] * (N)
br = [0] * (M)

ar[0] = A[0]
for i, v in enumerate(A):
    ar[i+1] = ar[i] + v

br[0] = B[0]
for i, v in enumerate(B):
    br[i+1] = br[i] + v

max_read = 0
j = M
for i in range(N+1):
    rest = K - ar[i]
    if rest <= 0:
        break
    while br[j] > K - ar[i]:
        j -= 1

    max_read = max(max_read, i+j)

print(max_read)

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_sum = []
a_sum = 0
for a in A:
    a_sum += a
    A_sum.append(a_sum)

B_sum = []
b_sum = 0
for b in B:
    b_sum += b
    B_sum.append(b_sum)

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

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

Submission status: Runtime Error

Solution code:
from collections import deque

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


consumptions_A = [0]
for Ai in A:
    consumptions_A.append(consumptions_A + Ai)

consumptions_B = []
for Bi in B:
    consumptions_B.append(consumptions_B + Bi)

answer = 0
j = M
for i in range(len(consumptions_A)):
    if (consumptions_A[i] > K): break

    remaining_time = K - consumptions_A[i]
    while consumptions_B[j] > remaining_time:
        j -= 1
    
    num_books = i + j
    answer = max(answer, num_books)

print(answer)

Submission status: Runtime Error

Solution code:
from collections import deque

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


consumptions_A = [0]
for Ai in A:
    consumptions_A.append(consumptions_A + Ai)

consumptions_B = []
for Bi in B:
    consumptions_B.append(sum(B[:i]))

answer = 0
j = M
for i in range(len(consumptions_A)):
    if (consumptions_A[i] > K): break

    remaining_time = K - consumptions_A[i]
    while consumptions_B[j] > remaining_time:
        j -= 1
    
    num_books = i + j
    answer = max(answer, num_books)

print(answer)

Submission status: Runtime Error

Solution code:

import bisect
import numpy

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

cost_a = numpy.insert(numpy.cumsum(a), 0, 0)
cost_b = numpy.insert(numpy.cumsum(b), 0, 0)

ans = 0
j =  len(cost_b) -1
for i in range(len(cost_a)):
    for j in range( j, 0, -1):
        if cost_a[i] + cost_b[j] <= k:
            ans  = i + j if ans < i + j else ans
            break
print(ans)
[root@local

Submission status: Runtime Error

Solution code:

import bisect
import numpy

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

cost_a = numpy.insert(numpy.cumsum(a), 0, 0)
cost_b = numpy.insert(numpy.cumsum(b), 0, 0)

ans = 0
j =  len(cost_b)
for i in range(len(cost_a)):
    for j in range( j, 0, -1):
        if cost_a[i] + cost_b[j] <= k:
            ans  = i + j if ans < i + j else ans
            break
print(ans)