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:
anum,bnum,acc = map(int,input().split())
alist = list(map(int,input().split()))
blist = list(map(int,input().split()))

asum = 0;bsum = 0
ans = 0;a = 0;b = 0
while asum + alist[a] <= acc:
    asum += alist[a];a+=1
    if a == anum:
        break

while asum + blist[b] <= acc:
    bsum += blist[b];b += 1
    if b == bnum:
        break

if a == 0 and b == 0:
    pass
elif (a == anum and b == bnum) or a == 0:
    ans = a + b
else:
    ans = a + b
    for i in range(a):
        while asum - alist[a-(i+1)] + bsum + blist[b] <= acc:
            bsum += blist[b];b += 1
            if a + b > ans:
                ans = a + b
            if b == bnum:
                break

print(ans)

Submission status: Runtime Error

Solution code:
anum,bnum,acc = map(int,input().split())
alist = list(map(int,input().split()))
blist = list(map(int,input().split()))

asum = 0;bsum = 0
ans = 0;a = 0;b = 0
while asum + alist[a] <= acc:
    asum += alist[a];a+=1
    if a == anum:
        break

while asum + blist[b] <= acc:
    bsum += blist[b];b += 1
    if b == bnum:
        break

if a == 0 and b == 0:
    pass
elif (a == anum and b == bnum) or a == 0:
    ans = a + b
else:
    ans = a + b
    for i in range(a):
        while asum - alist[a-(i+1)] + bsum + blist[b] <= acc:
            if b == bnum:
                break
            bsum += blist[b];b += 1
            if a + b > ans:
                ans = a + b

print(ans)

Submission status: Runtime Error

Solution code:
anum,bnum,acc = map(int,input().split())
alist = list(map(int,input().split()))
blist = list(map(int,input().split()))

asum = 0;bsum = 0
ans = 0;a = 0;b = 0
while asum + alist[a] <= acc:
    asum += alist[a];a+=1
    if a == anum:
        break

while asum + blist[b] <= acc:
    bsum += blist[b];b += 1
    if b == bnum:
        break

if a == 0 and b == 0:
    pass
elif (a == anum and b == bnum) or a == 0:
    ans = a + b
else:
    ans = a+b
    for i in range(1,a):
        while asum - alist[a-i] + bsum + blist[b] <= acc:
            if b == bnum:
                break
            bsum += blist[b];b += 1
            if a + b > ans:
                ans = a + b

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

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

total = 0

for i in range(N + M):
    if len(A) > 0 and A[0] <= B[0] and K - A[0] >= 0:
        K = K - A[0]
        A = A[1:]
        total += 1
    elif len(B) > 0 and K - B[0] >= 0:
        K = K - B[0]
        B = B[1:]
        total += 1
    else:
        break

print(total)

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
while k > 0:
    for i in range(n+m):
        if len(a) == 0:
            if len(b) == 0:
                k = 0
                break
            elif k >= b[0]:
                btop = b.pop(0)
                k -= btop
                count += 1
            else:
                k = 0
                break
        elif len(b) == 0:
            if len(a) == 0:
                k = 0
                break
            elif k >= a[0]:
                btop = a.pop(0)
                k -= atop
                count += 1
            else:
                k = 0
                break
                
        elif a[0] > k and b[0] > k:
            k = 0
            break
        elif b[0] >= a[0]:
            atop = a.pop(0)
            k -= atop
            count += 1
        elif a[0] > b[0]:
            btop = b.pop(0)
            k -= btop
            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
while k > 0:
    for i in range(n+m):
        if a[0] > k and b[0] > k:
            k = 0
            break
        elif b[0] >= a[0]:
            atop = a.pop(0)
            k -= atop
            count += 1
        elif a[0] > b[0]:
            btop = b.pop(0)
            k -= btop
            count += 1

print(count)

Submission status: Runtime Error

Solution code:
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
counta = 0
countb = 0
time = 0
book = 0
test = 0

for i in range(0,len(a) + len(b)):
  if counta == len(a) and k >= time + b[countb]:
    time += b[countb]
    countb += 1
  elif countb == len(b) and k >= time + a[counta]:
    time += a[counta]
    counta += 1
  elif a[counta] >= b[countb] and k >= time + b[countb]:
    time += b[countb]
    countb += 1
  elif a[counta] < b[countb] and k >= time + a[counta]:
    time += a[counta]
    counta += 1
  else:
    break

print(counta + countb)

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

cnt=0
A_sum_time=0
A_max_i=-1
temp=0
for i in range(N):
    temp+=A[i]
    if temp>K:
        break
    A_sum_time=temp
    A_max_i=i
    cnt+=1

A_only_cnt=cnt
sum_time=0
ans=A_only_cnt #最初の一時的な解はすべてAの場合
#print('すべてAの場合の冊数は{}'.format(A_max_i+1))

for i in range(A_max_i+1): #Aを何冊減らすか
    
    cnt=A_only_cnt #初期化
    new_A_sum_time=A_sum_time #初期化
    for j in range(i):
        new_A_sum_time -= A[A_max_i+1-i]
        cnt -= 1
    k=0 #Bを何冊目まで追加するか
    Flg=True

    #print('Aを{}冊減らしたときの時間は{}'.format(i,new_A_sum_time))
    sum_time=new_A_sum_time
    while Flg: #Bを何冊増やす
        sum_time=sum_time+B[k]
        if sum_time>K:
            Flg=False
        else:
            k += 1
            cnt= onlyA_cnt-i+k
            #print('Aを{}冊減らし、Bを{}冊増やした場合の冊数は{}、時間は{}'.format(i,k,cnt,sum_time))
        if k==M:
            Flg=False
    if cnt > ans:
        ans=cnt 

temp=0
cnt =0
if A_max_i<0:
    for i in range(M):
        temp+=B[i]
        if temp>K:
            break
        cnt+=1
    ans=cnt
    
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()))

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

j, ans = m, 0
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()))

cnt=0
A_sum_time=0
A_max_i=-1
temp=0
for i in range(N):
    temp+=A[i]
    if temp>K:
        break
    A_sum_time=temp
    A_max_i=i
    cnt+=1

A_only_cnt=cnt
sum_time=0
ans=A_only_cnt #最初の一時的な解はすべてAの場合
#print('すべてAの場合の冊数は{}'.format(A_max_i+1))

for i in range(A_max_i+1): #Aを何冊減らすか
    
    cnt=A_only_cnt #初期化
    new_A_sum_time=A_sum_time #初期化
    for j in range(i):
        new_A_sum_time -= A[A_max_i+1-i]
        cnt -= 1
    k=0 #Bを何冊目まで追加するか
    Flg=True

    #print('Aを{}冊減らしたときの時間は{}'.format(i,new_A_sum_time))
    sum_time=new_A_sum_time
    while Flg: #Bを何冊増やす
        sum_time=sum_time+B[k]
        if sum_time>K:
            Flg=False
        else:
            k += 1
            cnt= onlyA_cnt-i+k
            #print('Aを{}冊減らし、Bを{}冊増やした場合の冊数は{}、時間は{}'.format(i,k,cnt,sum_time))
        if k==M:
            Flg=False
    if cnt > ans:
        ans=cnt 

temp=0
cnt =0
if A_max_i==0:
    for i in range(M):
        temp+=B[i]
        if temp>K:
            break
        cnt+=1
    ans=cnt
    
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()))

cnt=0
A_sum_time=0
A_max_i=-1
temp=0
for i in range(N):
    temp+=A[i]
    if temp>K:
        break
    A_sum_time=temp
    A_max_i=i
    cnt+=1

A_only_cnt=cnt
sum_time=0
ans=A_only_cnt #最初の一時的な解はすべてAの場合
#print('すべてAの場合の冊数は{}'.format(A_max_i+1))

for i in range(A_max_i+1): #Aを何冊減らすか
    
    cnt=A_only_cnt #初期化
    new_A_sum_time=A_sum_time #初期化
    for j in range(i):
        new_A_sum_time -= A[A_max_i+1-i]
        cnt -= 1
    k=0 #Bを何冊目まで追加するか
    Flg=True

    #print('Aを{}冊減らしたときの時間は{}'.format(i,new_A_sum_time))
    sum_time=new_A_sum_time
    while Flg: #Bを何冊増やす
        sum_time=sum_time+B[k]
        if sum_time>K:
            Flg=False
        else:
            k += 1
            cnt= onlyA_cnt-i+k
            #print('Aを{}冊減らし、Bを{}冊増やした場合の冊数は{}、時間は{}'.format(i,k,cnt,sum_time))
        if k==M:
            Flg=False
    if cnt > ans:
        ans=cnt 

temp=0
cnt =0
if A_max_i=0:
    for i in range(M):
        temp+=B[i]
        if temp>K:
            break
        cnt+=1
    ans=cnt
    
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()))

cnt=0
A_sum_time=0
A_max_i=-1
temp=0
for i in range(N):
    temp+=A[i]
    if temp>K:
        break
    A_sum_time=temp
    A_max_i=i
    cnt+=1

A_only_cnt=cnt
sum_time=0
ans=A_only_cnt #最初の一時的な解はすべてAの場合
#print('すべてAの場合の冊数は{}'.format(A_max_i+1))

for i in range(A_max_i+1): #Aを何冊減らすか
    
    cnt=A_only_cnt #初期化
    new_A_sum_time=A_sum_time #初期化
    for j in range(i):
        new_A_sum_time -= A[A_max_i+1-i]
        cnt -= 1
    k=0 #Bを何冊目まで追加するか
    Flg=True

    #print('Aを{}冊減らしたときの時間は{}'.format(i,new_A_sum_time))
    sum_time=new_A_sum_time
    while Flg: #Bを何冊増やす
        sum_time=sum_time+B[k]
        if sum_time>K:
            Flg=False
        else:
            k += 1
            cnt= onlyA_cnt-i+k
            #print('Aを{}冊減らし、Bを{}冊増やした場合の冊数は{}、時間は{}'.format(i,k,cnt,sum_time))
        if k==M:
            Flg=False
    if cnt > ans:
        ans=cnt 
    
print(ans)

Submission status: Runtime Error

Solution code:
cnt=0
A_sum_time=0
A_max_i=-1
temp=0
for i in range(N):
    temp+=A[i]
    if temp>K:
        break
    A_sum_time=temp
    A_max_i=i
    cnt+=1

A_only_cnt=cnt
sum_time=0
ans=A_only_cnt #最初の一時的な解はすべてAの場合
#print('すべてAの場合の冊数は{}'.format(A_max_i+1))

for i in range(A_max_i+1): #Aを何冊減らすか
    
    cnt=A_only_cnt #初期化
    new_A_sum_time=A_sum_time #初期化
    for j in range(i):
        new_A_sum_time -= A[A_max_i+1-i]
        cnt -= 1
    k=0 #Bを何冊目まで追加するか
    Flg=True

    #print('Aを{}冊減らしたときの時間は{}'.format(i,new_A_sum_time))
    sum_time=new_A_sum_time
    while Flg: #Bを何冊増やす
        sum_time=sum_time+B[k]
        if sum_time>K:
            Flg=False
        else:
            k += 1
            cnt= onlyA_cnt-i+k
            #print('Aを{}冊減らし、Bを{}冊増やした場合の冊数は{}、時間は{}'.format(i,k,cnt,sum_time))
        if k==M:
            Flg=False
    if cnt > ans:
        ans=cnt 
    
print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

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

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

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

total_time = 0
count = 0

while total_time < k:
    if len(a_time_list) == 0 and len(b_time_list) == 0:
        break
    elif total_time + a_time_list[0] > k or total_time + b_time_list[0] > k:
        break

    if len(a_time_list) == 0:
        total_time += b_time_list.pop(0)
    elif len(b_time_list) == 0:
        total_time += a_time_list.pop(0)
    else:
        if a_time_list[0] <= b_time_list[0]:
            total_time += a_time_list.pop(0)
        elif a_time_list > b_time_list[0]:
            total_time += b_time_list.pop(0)

    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()))
A.reverse()
B.reverse()

l = 0
def d(x):
    global l
    if A:
        x.append(A.pop())
        if sum(x) <= K:
            l = max(l, len(x))
            d(x)
        A.append(x.pop())
    if B:
        x.append(B.pop())
        if sum(x) <= K:
            l = max(l, len(x))
            d(x)
        B.append(x.pop())

d([])
print(l)

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.reverse()
B.reverse()

def d(x, l):
    if A:
        x.append(A.pop())
        if sum(x) <= K:
            l.append(len(x))
            d(x, l)
        A.append(x.pop())

    if B:
        x.append(B.pop())
        if sum(x) <= K:
            l.append(len(x))
            d(x, l)
        B.append(x.pop())

ans = []
d([], ans)
print(max(ans) if len(ans) != 0 else 0)

Submission status: Runtime Error

Solution code:
# https://atcoder.jp/contests/abc172/tasks/abc172_c


def eval(A, B, K):
    C = 0

    if K == 0:
        return 0

    while (A and K >= A[0]) or (B and K >= B[0]):
        C += 1
        if A and B:
            if A[0] == B[0]:
                i = j = 0
                while A[i] == B[j] and i < len(A) and j < len(B):
                    i += 1
                    j += 1
                if i == len(A) and j == len(B):
                    K -= A.pop(0)
                    B.pop(0)
                if A[i] < B[j]:
                    K -= A.pop(0)
                else:
                    K -= B.pop(0)
            if A[0] < B[0]:
                K -= A.pop(0)
            else:
                K -= B.pop(0)
        elif A:
            K -= A.pop(0)
        else:
            K -= B.pop(0)


    return C



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

Submission status: Runtime Error

Solution code:
from math import *
def main():
    
    n,m,k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    ans = 0
    ms = 0
    if a[-1] > k or b[-1] > k:
        print(0)
        return
    while ms < k:
        if not (a[-1] > k or b[-1] > k):
            if len(b) > 0 and len(a) > 0:
                if a[-1] > b[-1]:
                    ms += b[-1]
                    b.pop()
                    ans += 1
                elif len(a) > 0:
                    ms += a[-1]
                    a.pop()
                    ans += 1
            elif len(a) > 0:
                ms += a[-1]
                a.pop()
                ans += 1
            elif len(b) > 0:
                ms += b[-1]
                b.pop()
                ans += 1
    print(ans)
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()))
  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,l=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
time=0
c=0
while(time<l):
    if(len(a)==0 ):
        time=time+b[0]
        b.pop(0)
        if(time>l):
            break
        else:
            c=c+1
    elif(len(b)==0):
        time=time+a[0]
        a.pop(0)
        if(time>l):
            break
        else:
            c=c+1
    if( len(a)>0 and len(b)>0 and b[0]>=a[0]):
        time=time+a[0]
        a.pop(0)
        if(time>l):
            break
        else:
            c=c+1
    elif(len(a)>0 and len(b)>0 and a[0]>=b[0]):
        time=time+b[0]
        b.pop(0)
        if(time>l):
            break
        else:
            c=c+1
    if(time>=l):
        break
    print(time,a,b)
print(c)

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

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

sa = [0]
sb = [0]

for i in range(n):
    sa.append(sa[i]+a[i])

for i in range(m):
    sb.append(sb[i]+b[i])

ans = 0
j = m

#しゃくとり
for i in in range(n+1):
    if sa[i] > k:
        break
    while sa[i]+sb[j] > k:
        j -= 1
    ans = max(ans, i+j)

print(ans)

Submission status: Runtime Error

Solution code:
def c(x):
    if sb[x] + S <= k: return True
    else: return False


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

sa = []
sb = []

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

if b[0] <= k:
    sb.append(b[0])
    for j in range(1, m):
        if sb[j-1]+b[j] > k:
            break
        sb.append(sb[j-1]+b[j])

if len(sa) == 0:
    print(len(sb))
    exit()

ans = len(sa)

for i in range(len(sa))[::-1]:
    mb = 0
    lb = len(sb) - 1
    if len(sb) == 0 or sa[i] + sb[0] > k:
        print(len(sa))
        exit()
    
    while lb - mb > 1:
        mid = (mb+lb)//2
        if c(mid):
            mb = mid
        else:
            lb = mid
    ans = max(ans, i+1+lb)

print(ans)

Submission status: Runtime Error

Solution code:
def c(x):
    if sb[x] + S <= k: return True
    else: return False


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

sa = []
sb = []

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

if b[0] <= k:
    sb.append(b[0])
    for j in range(1, m):
        if sb[j-1]+b[j] > k:
            break
        sb.append(sb[j-1]+b[j])

if len(sa) == 0:
    print(len(sb))
    sys.exit()

for i in range(len(sa))[::-1]:
    mb = 0
    lb = len(sb) - 1
    if len(sb) == 0 or sa[i] + sb[0] > k:
        print(len(sa))
        sys.exit()
    
    while lb - mb > 1:
        mid = (mb+lb)//2
        if c(mid):
            mb = mid
        else:
            lb = mid
    ans = max(ans, i+1+lb)

print(ans)

Submission status: Runtime Error

Solution code:
def c(x):
    if sb[x] + S <= k: return True
    else: return False


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

sa = []
sb = []

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

if b[0] <= k:
    sb.append(b[0])
    for j in range(1, m):
        if sb[j-1]+b[j] > k:
            break
        sb.append(sb[j-1]+b[j])

if len(sa) == 0:
    print(len(sb))
    exit()

for i in range(len(sa))[::-1]:
    mb = 0
    lb = len(sb) - 1
    if len(sb) == 0 or sa[i] + sb[0] > k:
        print(len(sa))
        exit()
    
    while lb - mb > 1:
        mid = (mb+lb)//2
        if c(mid):
            mb = mid
        else:
            lb = mid
    ans = max(ans, i+1+lb)

print(ans)

Submission status: Runtime Error

Solution code:
def c(x):
    if sb[x] + S <= k: return True
    else: return False


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

sa = []
sb = []

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

if b[0] <= k:
    sb.append(b[0])
    for j in range(1, m):
        if sb[j-1]+b[j] > k:
            break
        sb.append(sb[j-1]+b[j])

if len(sa) == 0:
    print(len(sb))
    exit()

for i in range(len(sa))[::-1]:
    mb = 0
    lb = len(sb)
    S = sa[i]
    if lb == 0 or S + sb[0] > k:
        print(len(sa))
        exit()
    
    while lb - mb > 1:
        mid = (mb+lb)//2
        if c(mid):
            mb = mid
        else:
            lb = mid
    ans = max(ans, i+1+lb)

print(ans)

Submission status: Runtime Error

Solution code:
n,m,k = map(int,input().split())
arr0 = list(map(int,input().split()))
arr1 = list(map(int,input().split()))
acc0 = [0]

for i in range(n):
  acc0.append(acc0[-1] + arr0[i])
acc1 = [0]
for i in range(m):
  acc1.append(acc1[-1] + arr1[i])
ans = 0
j = m
for i in range(n+1):
  if acc0[i] > k:
    break
  while acc1[j] > k - acc0[i] and j > 0:
    j -= 1
  ans = max(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()))

i=0
j=0
a=0


while a<K and i<N:
  a+=A[i]
  i+=1
if a>K:
  i-=1
  a-=A[i]
  
while a<K and j<M:
  a+=B[j]
  j+=1
if a>K:
  j-=1
  a-=B[j]

i-=1

if j<M and A[0]<K:
  while A[i]>=B[j]:
    a-=A[i]
    i-=1
    a+=B[j]
    j+=1
  
print(i+1+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()))

i=0
j=0
a=0

while a<K and i<N:
  a+=A[i]
  i+=1
if a>K:
  i-=1
  a-=A[i]
  
while a<K and j<M:
  a+=B[j]
  j+=1
if a>K:
  j-=1
  a-=B[j]

i-=1

if j<M:
  while A[i]>=B[j]:
    a-=A[i]
    i-=1
    a+=B[j]
    j+=1
  
print(i+1+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()))

i=0
j=0
a=0

while a<=K and i<N:
  a+=A[i]
  i+=1
if a>K:
  i-=1
  a-=A[i]
  
while a<=K and j<M:
  a+=B[j]
  j+=1
if a>K:
  j-=1
  a-=B[j]

i-=1

if j<M:
  while A[i]>=B[j]:
    a-=A[i]
    i-=1
    a+=B[j]
    j+=1
  
print(i+1+j)

Submission status: Runtime Error

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

N = a[0]
M = a[1]
K = a[2]

count = 0 #読んだ冊数を記録
count_time = 0 #読んだ時間を記録

if K<A[0] or K<B[0]:
    pass
 
else:
    while K > count_time:
        if len(A)!=0 and len(B)!=0:
            if A[0] >= B[0]:
                count_time += B[0]
                count += 1
                B.pop(0)

            if A[0] < B[0]:
                count += 1
                count_time += A[0]
                A.pop(0)

        elif len(A)==0 and len(B)!=0:
            count += 1
            count_time += B[0]
            B.pop(0)

        elif len(B)==0 and len(A)!=0:
            count += 1
            count_time += A[0]
            A.pop(0)

        else:
            count += 1
            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()))

a, b = [0], [0]

for i in range(N):
  a.append(a[i] + A[i])
  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()))

a, b = [0], [0]

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

ans, j = 0, 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())
#n A book number,m B,k minutes
a=list()
b=list()
s=0
t=0
ikiti=0
result=0
while ikiti=0:
  if a[s]>b[t]:
    if k-b[t]>=0:
      k=k-b[t]
      t=t+1
      result=result+1
    else:
      ikiti=1
  else:
    if k-a[s]>=0:
      k=k-a[s]
      s=s+1
      result=result+1
    else:
      ikiti=1
print(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()))
p,q = 0,0
T = 0
ret = 0
for i in range(N):
  K_ = K
  K_ -= sum(A[:i])
  if K_ == 0:
    ret = max(ret,i):
    break
  elif K_ < 0:
    ret = max(ret, i - 1)
    break
  for j in range(M):
    K_ -= B[j]
    if K_ == 0:
      tmp = i + (j + 1)
      ret = max(ret, tmp)
      break
    elif K_ < 0:
      tmp = i + j
      break
print(ret)

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

s = 0
t = 0
for i in range(n+m):
    if a != []:
        if a[0] <= b[0]:
            c = a[0]
            a.pop(0)
        else:
            c = b[0]
            b.pop(0)
    else:
        c = b[0]
        b.pop(0)
    if s+c>k:
        break
    else:
        s += c
        t += 1
print(t)

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

s = 0
t = 0
for i in range(n+m):
    if a != []:
        c = min(a[0],b[0])
        if c == a[0]:
            a.pop(0)
        else:
            b.pop(0)
    else:
        c = b[0]
        b.pop(0)
    if k-c < s:
        break
    else:
        s += c
        t += 1
print(t)

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
while True:
    if A[0]-B[0] >= 0:
        K -= B[0]
        if K >= 0:
            count += 1
            B.pop(0)
        else:
            break
    else:
        K -= A[0]
        if K >= 0 :
            count += 1
            A.pop(0)
        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()))

count = 0
while True:
    if A[0]-B[0] >= 0:
        K = K-B[0]
        if K >= 0 :
            count += 1
            B.pop(0)
        else:
            break

    else:
        K = K-A[0]
        if K >= 0 :
            count += 1
            A.pop(0)
        else:
            break        
print(count)

Submission status: Runtime Error

Solution code:
from collections import deque
n,m,k = map(int,input().split())
a = deque(map(int,input().split()))
b = deque(map(int,input().split()))
if sum(a)+sum(b)<=k:
    print(n+m)
    exit()
num = 0
cnt = -1
for i in range(n+m):
    if num>k:
        break
    elif a == () and b == ():
        break
    elif a == ():
        num += b[0]
        cnt +=1
        b.popleft()
    elif b == ():
        num += a[0]
        cnt += 1
        a.popleft()
    elif a[0] <= b[0]:
        num += a[0]
        cnt += 1
        a.popleft()
    else:
        num += b[0]
        cnt += 1
        b.popleft()
print(cnt)

Submission status: Runtime Error

Solution code:
from collections import deque
n,m,k = map(int,input().split())
a = deque(map(int,input().split()))
b = deque(map(int,input().split()))
if sum(a)+sum(b)<=k:
    print(n+m)
    exit()
num = 0
cnt = -1
for i in range(n+m):
    if num>k:
        break
    elif a == [] and b == []:
        break
    elif a == []:
        num += b[0]
        cnt +=1
        b.popleft()
    elif b == []:
        num += a[0]
        cnt += 1
        a.popleft()
    elif a[0] <= b[0]:
        num += a[0]
        cnt += 1
        a.popleft()
    else:
        num += b[0]
        cnt += 1
        b.popleft()
print(cnt)

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()))
if sum(a)+sum(b)<=k:
    print(n+m)
    exit()
num = 0
cnt = -1
for i in range(n+m):
    if num>k:
        break
    elif a == [] and b == []:
        break
    elif a == []:
        num += b[0]
        cnt +=1
        b.popleft()
    elif b == []:
        num += a[0]
        cnt += 1
        a.popleft()
    elif a[0] <= b[0]:
        num += a[0]
        cnt += 1
        a.popleft()
    else:
        num += b[0]
        cnt += 1
        b.popleft()
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()))
if sum(a)+sum(b)<=k:
    print(n+m)
    exit()
num = 0
cnt = -1
for i in range(n+m):
    if num>k:
        break
    elif a[0] <= b[0]:
        num += a[0]
        cnt += 1
        del a[0]
    else:
        num += b[0]
        cnt += 1
        del b[0]
print(cnt)