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

 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:
def readable(A, B, K):
    books_num = 0
    time = 0
    
    while(time < K):
        if len(A) == 0 and len(B) == 0:
            break
        elif len(A) != 0 and len(B) != 0:
            if A[0] < B[0]:
                time += A[0]
                temp = A[0]
                A.remove(A[0])
            else:
                time += B[0]
                temp = B[0]
                B.remove(B[0])
        elif len(A) == 0:
            time += B[0]
            temp = B[0]
            B.remove(B[0])
        elif len(B) == 0:
            time += A[0]
            temp = B[0]
            A.remove(A[0])
        if time <= K:
            books_num += 1
        
    return books_num

if __name__ == "__main__":
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    print(readable(A, B, K))

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=A[0]
b=sum(B)
p=0
for i in range(N):
    count=a+b
    while count>K:
        count-=B[M-1]
        M-=1
    if i!=N-1:
        a+=A[i+1]
    p=max(p,i+M+1)
    if a>K:
        break
print(p)

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

if k < a[0] and k < b[0]:
    print(0)
    sys.exit()

t = 0
ai = 0
bi = 0
count = 0
while k > t:
    if ai == n:
        t += b[bi]
        bi += 1
        count += 1
    elif bi == m:
        t += a[ai]
        ai += 1
        count += 1
    elif ai == n and bi == m:
        break
    else:
        if a[ai] < b[bi]:
            t += a[ai]
            ai += 1
            count += 1
        elif a[ai] > b[bi]:
            t += b[bi]
            bi += 1
            count += 1
        else:
            if a[ai] > b[bi+1]:
                t += b[bi]
                ai += 1
                count += 1
            elif a[ai+1] < b[bi]:
                t += a[ai]
                bi += 1
                count += 1
if t > k:
    count -= 1
    print(count)
else:
    print(count)

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

if k < a[0] and k < b[0]:
    print(0)
    sys.exit()

t = 0
ai = 0
bi = 0
count = 0
while k > t:
    if ai == n:
        t += b[bi]
        bi += 1
        count += 1
    elif bi == n:
        t += a[ai]
        ai += 1
        count += 1
    elif ai == n and bi == n:
        break
    else:
        if a[ai] <  b[bi]:
            t += a[ai]
            ai += 1
            count += 1
        elif a[ai] >  b[bi]:
            t += b[bi]
            bi += 1
            count += 1
        else:
            if ai + 1 == n:
                t += a[ai]
                ai += 1
                count += 1
            elif bi + 1 == m:
                t += b[bi]
                bi += 1
                count += 1
            elif a[ai] > b[bi+1]:
                t += b[bi]
                ai += 1
                count += 1
            elif a[ai+1] < b[bi]:
                t += a[ai]
                bi += 1
                count += 1
if t > k:
    count -= 1
    print(count)
else:
    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()))
#print(a)
asum=[]
bsum=[]
cnt=0
for i in range(n):
    cnt+=a[i]
    asum.append(cnt)
    if cnt>k:
        amx=i
        break
    amx=i
#print("amx=",amx)

cnt=0
for i in range(m):
    cnt+=b[i]
    bsum.append(cnt)
    if cnt>k:
        bmx=i
        break
    bmx=i
#print("bmx=",bmx)

ans=0
for i in range(amx+1):
    c=k-asum[i]
#    print("i=",i)
#    print("c=",c)
    if c<0:
        continue
    elif i==0:
#        for j in range(bmx,0,-1):
        for j in reversed(range(0,bmx+1)):
#            print(j)
#            print(bsum[j])
            if c>=bsum[j]:
                tmp=i+j+2
                l=j
#                print("l=",l)
                break
    else:
        while(c<bsum[l]):
            l-=1
        tmp=i+l+2
    ans=max(ans,tmp)
#    print("ans=",ans)
print(ans)

Submission status: Runtime Error

Solution code:
n,m,k=input().split()
a=input().split()
b=input().split()
ta=0
cnta=0
while int(cnta)<int(n) and ta+int(a[cnta])<=int(k) :
    ta= ta+ int(a[cnta])
    cnta=cnta+1
tb=0
cntb=0
while cntb<int(m) and ta+tb+int(b[cntb])<=int(k):
    tb = tb+ int(b[cntb])
    cntb=cntb+1 
ans=cnta+cntb

while cnta<=0:
    ta=ta-int(a[cnta])
    cnta=cnta-1
    while cntb<int(m) and ta+tb+int(b[cntb])<=int(k):
        tb= tb+ int(b[cntb])
        cntb=cntb+1
    ans=max(ans,cnta+cntb)
print(ans)

Submission status: Runtime Error

Solution code:
N, M, K = input().split()
A = input().split()
B = input().split()
ta = 0
cnta = 0
while cnta < int(N) and ta + int(A[cnta]) <= int(K):
    ta += int(A[cnta])
    cnta+=1

tb = 0
cntb = 0
while cntb < int(M) and ta + tb + int(B[cntb]) <= int(K):
    tb += int(B[cntb])
    cntb += 1
    
ans = cnta + cntb

while cnta >= 0:
    ta -= int(A[cnta])
    cnta -= 1
    while cntb < int(M) and ta + tb + int(B[cntb]) <= int(K):
        tb += int(B[cntb])
        cntb += 1
    ans = max(ans, cnta + cntb)

print(ans)

Submission status: Runtime Error

Solution code:
m,n,k=input().split()
a=input().split()
b=input().split()
ta=0
cnta=0
while ta+int(a[cnta])<=int(k) and int(cnta)<int(n):
    ta= ta+ int(a[cnta])
    cnta=cnta+1
tb=0
cntb=0
while cntb<int(m) and ta+tb+int(b[cntb])<=int(k):
    tb = tb+ int(b[cntb])
    cntb=cntb+1 
ans=cnta+cntb

while cnta<=0:
    ta=ta-int(a[cnta])
    cnta=cnta-1
    while cntb<int(m) and ta+tb+int(b[cntb])<=int(k):
        tb= tb+ int(b[cntb])
        cntb=cntb+1
    ans=max(ans,cnta+cntb)
print(ans)

Submission status: Runtime Error

Solution code:
m,n,k=input().split()
a=input().split()
b=input().split()
ta=0
cnta=0
while ta+int(a[cnta])<=int(k) and int(cnta)<int(n):
    ta= ta+ int(a[cnta])
    cnta=cnta+1
tb=0
cntb=0
while cntb<int(m) and ta+tb+int(b[cntb])<=int(k):
    tb = tb+ int(b[cntb])
    cntb=cntb+1 
ans=cnta+cntb

while cnta<=0:
    ta=ta-a[cnta]
    cnta=cnta-1
    while cntb<int(m) and ta+tb+int(b[cntb])<=int(k):
        tb= tb+ int(b[cntb])
        cntb=cntb+1
    ans=max(ans,cnta+cntb)
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()))

# bを読むのにかかる時間
t = 0

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

# bを全部読む
j = m
ans = 0

for i in range(n+1):
    # bで読む本を1冊ずつ諦めていく
    while j > 0 and t > k:
        j -= 1
        t -= b[i]
    
    # 諦められる本すらない場合
    if t > k:
        break

    ans = max(ans, i+j)
    
    # 配列外参照を防ぐ
    if i == n:
        break
    
    # aで読む本を1冊増やす
    t += a[i]

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
i = 0
j = 0
while k >= 0:
    if i >= len(a) and j >= len(b):
        break

    if i >= len(a):
        if k >= b[i]:
            k -= b[i]
            j += 1
            cnt += 1
        else:
            break
        continue
    if j >= len(b):
        if k >= a[i]:
            k -= a[i]
            i += 1
            cnt += 1
        else:
            break
        continue

    if a[i] >= b[j]:
        if k >= a[i]:
            k -= a[i]
            i += 1
            cnt += 1
        else:
            break
    else:
        if k >= b[i]:
            k -= b[i]
            j += 1
            cnt += 1
        else:
            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()))

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 sys
n, m, k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

if k < a[0] and k < b[0]:
    print(0)
    sys.exit()

t = 0
ai = 0
bi = 0
count = 0
while k > t:
    if ai == n:
        t += b[bi]
        bi += 1
        count += 1
    elif bi == n:
        t += a[ai]
        ai += 1
        count += 1
    else:
        if a[ai] > b[bi]:
            t += a[ai]
            ai += 1
            count += 1
        elif a[ai] < b[bi]:
            t += b[bi]
            bi += 1
            count += 1
        else:
            if ai + 1 == n:
                t += a[ai]
                ai += 1
                count += 1
            elif bi + 1 == m:
                t += b[bi]
                bi += 1
                count += 1
            elif a[ai+1] > b[bi+1]:
                t += a[ai]
                ai += 1
                count += 1
            elif a[ai+1] < b[bi+1]:
                t += b[bi]
                bi += 1
                count += 1
print(count)

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

if k < a[0] or k < b[0]:
    print(0)
    sys.exit()

t = 0
ai = 0
bi = 0
count = 0
while k > t:
    if ai == n:
        t += b[bi]
        bi += 1
        count += 1
    elif bi == n:
        t += a[ai]
        ai += 1
        count += 1
    else:
        if a[ai] > b[bi]:
            t += a[ai]
            ai += 1
            count += 1
        elif a[ai] < b[bi]:
            t += b[bi]
            bi += 1
            count += 1
        else:
            if ai + 1 == n:
                t += a[ai]
                ai += 1
                count += 1
            elif bi + 1 == m:
                t += b[bi]
                bi += 1
                count += 1
            elif a[ai+1] > b[bi+1]:
                t += a[ai]
                ai += 1
                count += 1
            elif a[ai+1] < b[bi+1]:
                t += b[bi]
                bi += 1
                count += 1
print(count)

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

if k < a[0] or k < b[0]:
    print(0)
    sys.exit()

t = 0
ai = 0
bi = 0
count = 0
while k > t:
    if ai == n:
        t += b[bi]
        bi += 1
        count += 1
    elif bi == n:
        t += a[ai]
        ai += 1
        count += 1
    else:
        if a[ai] > b[bi]:
            t += a[ai]
            ai += 1
            count += 1
        elif a[ai] < b[bi]:
            t += b[bi]
            bi += 1
            count += 1
        else:
            if ai + 1 == n:
                t += a[ai]
                ai += 1
                count += 1
            elif bi + 1 == m:
                t += b[bi]
                bi += 1
                count += 1
            elif a[ai+1] > b[bi+1]:
                t += a[ai]
                ai += 1
                count += 1
            elif a[ai+1] < b[bi+1]:
                t += b[bi]
                bi += 1
                count += 1
    print(t)
print(count)

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

if k < a[0] and k < b[0]:
    print(0)
    sys.exit()

t = 0
ai = 0
bi = 0
count = 0
while k > t:
    if ai == n:
        t += b[bi]
        bi += 1
        count += 1
    elif bi == n:
        t += a[ai]
        ai += 1
        count += 1
    else:
        if a[ai] > b[bi]:
            t += a[ai]
            ai += 1
            count += 1
        elif a[ai] < b[bi]:
            t += b[bi]
            bi += 1
            count += 1
        else:
            if ai + 1 == n:
                t += a[ai]
                ai += 1
                count += 1
            elif bi + 1 == m:
                t += b[bi]
                bi += 1
                count += 1
            elif a[ai+1] > b[bi+1]:
                t += a[ai]
                ai += 1
                count += 1
            elif a[ai+1] < b[bi+1]:
                t += b[bi]
                bi += 1
                count += 1
    print(t)
print(count)

Submission status: Runtime Error

Solution code:
import bisect

def main():
    N, M, K = map(int, input().split())
    A = [int(v) for v in input().split()]
    B = [int(v) for v in input().split()]
    if N < M:
        for _ in range(M-N):
            A.append(0)
    else:
        for _ in range(N-M):
            B.append(0)
    C = [v1+v2 for v1, v2 in zip(A, B)]
    ruisekiA = [0 for _ in range(len(C)+1)]
    ruisekiB = [0 for _ in range(len(C)+1)]
    ruisekiC = [0 for _ in range(len(C)+1)]
    for i in range(len(C)):
        ruisekiA[i + 1] = ruisekiA[i] + A[i]
        ruisekiB[i + 1] = ruisekiB[i] + B[i]
        ruisekiC[i + 1] = ruisekiC[i] + C[i]

    ans = 0
    # i番目までは両方読む
    for i in range(len(C)+1):
        tans = i * 2
        tk = K - ruisekiC[i]
        if tk < 0:
            continue

        # A だけ、Bだけで何冊読めるか考える
        idx_a = bisect.bisect_left(ruisekiA, tk + ruisekiA[i])
        if ruisekiA[idx_a] != tk + ruisekiA[i]:
            idx_a -= 1
        idx_b = bisect.bisect_left(ruisekiB, tk + ruisekiB[i])
        if ruisekiB[idx_b] != tk + ruisekiB[i]:
            idx_b -= 1
        ans = max(ans, max(tans+idx_a-i, tans+idx_b-i))
    print(ans)


if __name__ == '__main__':
    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()))
time=0
a,b=0,0
if K>=sum(A)+sum(B):
  print(N+M)
else:
  while time<=K and a<=N and b<=M:
    if A[a]<=B[b]:
      time+=A[a]
      #print(f"A{A[a]}")
      a+=1
    else:
      time+=B[b]
      #print(f"B{B[b]}")
      b+=1
  if a==N+1:
    a=N
    while time<=K :
      time+=B[b]
      b+=1
  if b==M+1:
    b=M
    while time<=K :
      time+=A[a]
      a+=1
  print(a+b-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()))
time=0
a,b=0,0
if K>=sum(A)+sum(B):
  print(N+M)
else:
  while time<=K and a<=N and b<=M:
    if A[a]<=B[b]:
      time+=A[a]
      print(f"A{A[a]}")
      a+=1
    else:
      time+=B[b]
      print(f"B{B[b]}")
      b+=1
  if a==N+1:
    a=N
    while time<=K :
      time+=B[b]
      b+=1
  if b==M+1:
    b=M
    while time<=K :
      time+=A[a]
      a+=1
  print(a+b-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()))

count = 0
j = 0

for i in range(N + M):
  if(len(A)!=0 and A[0] <=  B[0]):
    j = A[0]
    del A[0]
  else:
    j = B[0]
    del B[0]
  if j <= K:
    K -= j
    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()))

a,b=[0],[0]
for i in range(n):
  a.apppend(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:
s = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))

total = 0
count = 0
ai = 0
bi = 0
aend = False
bend = False
while True:
    # print(total)
    if total > s[2]:
        break

    if ai == s[0]:
        aend = True
    if bi == s[1]:
        bend = True

    # print(ai, s[0], aend, bi, s[1], bend)
    if aend and bend:
        break

    if not aend and a[ai] < b[bi]:
        total += a[ai]
        ai += 1
    elif not bend:
        total += b[bi]
        bi += 1

    if total > s[2]:
        break

    count += 1

print(count)

Submission status: Runtime Error

Solution code:
# vim: fileencoding=utf-8


def main():
    k = int(input().split()[2])
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    r = 0
    while True:
        read = 0
        if len(a) != 0 and len(b) != 0:
            ai = a.index(min(a))
            bi = b.index(min(b))
            sa = sum(a[: ai + 1])
            sb = sum(b[: bi + 1])
            if sa < sb:
                read = a[0]
                a = a[1:]
            else:
                read = b[0]
                b = b[1:]
        elif len(a) == 0:
            bi = b.index(min(b))
            sb = sum(b[: bi + 1])
            read = b[0]
            b = b[1:]
        else len(b) == 0:
            ai = a.index(min(a))
            sa = sum(a[: ai + 1])
            read = a[0]
            a = a[1:]
        else:
            break
        k -= read
        if k < 0:
            break
        r += 1
        if k == 0:
            break
    print(r)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import bisect

N, M, K = input().split()

desk1 = list(map(int, input().split()))
desk2 = list(map(int, input().split()))

max_time = int(K)
item1 = [0]
item2 = [0]
for i in desk1:
    item1.append(item1[-1] + i)
for i in desk2:
    item2.append(item2[-1] + i)

ret = 0
for i, t in enumerate(item1):
    remain_time = max_time - t
    if remain_time > 0:
        j = bisect.bisect(item2, remain_time) - 1
        if j < 0:
            j = 0
        ret = max(ret, i + j)
    else:
        ret = max(ret, i)
print(ret)import bisect

N, M, K = input().split()

desk1 = list(map(int, input().split()))
desk2 = list(map(int, input().split()))

max_time = int(K)
item1 = [0]
item2 = [0]
for i in desk1:
    item1.append(item1[-1] + i)
for i in desk2:
    item2.append(item2[-1] + i)

ret = 0
for i, t in enumerate(item1):
    remain_time = max_time - t
    if remain_time > 0:
        j = bisect.bisect(item2, remain_time) - 1
        if j < 0:
            j = 0
        ret = max(ret, i + j)
    else:
        ret = max(ret, i)
print(ret)

Submission status: Runtime Error

Solution code:
/*
g++ -std=c++14 -o2 -Wall ABC.cpp -o .\ABC.out
.\ABC.out
*/

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int a[200010];
int b[200010];

int main(){
  int n,m,k;
  cin >> n >> m >> k;
  for (int i=0; i<n; ++i) cin >> a[i];
  for (int i=0; i<m; ++i) cin >> b[i];
  int r;
  int ap=0;
  int bp=0;
  int ans=0;
  while (r < k) {
    int c=0;
    if ((ap<m && bp<n && a[ap] < b[ap]) || (ap<m&&bp==n)) {
      c=a[ap];
      if (r+c<=k) {
        r += c;
        ++ans;
        ++ap;
      } else {break;}
    } else if ((ap<m && bp<n) || (ap==m&&bp<n)) {
      c=b[bp];
      if (r+c<=k) {
        r += c;
        ++ans;
        ++bp;
      } else {break;}
    } else {
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

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_num = 0
b_num = 0
while True:
    if a_num == len(a) and b_num == len(b):
        break
    elif b_num == len(b) and a[b_num] <= k and a_num < len(a):
        k -= a[a_num]
        a_num += 1
        continue
    elif a_num == len(a) and b[b_num] <= k and b_num < len(b):
        k -= b[b_num]
        b_num += 1
        continue
    elif a[a_num] <= k and a[a_num] <= b[b_num] and a_num < len(a):
        k -= a[a_num]
        a_num += 1
        continue
    elif b[b_num] <= k and b[b_num] < a[a_num] and b_num < len(b):
        k -= b[b_num]
        b_num += 1
        continue
    else:
        break
print(a_num + b_num)

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_num = 0
b_num = 0
while True:
    if a_num == len(a) and b_num == len(b):
        break
    elif a[b_num] <= k and b_num == len(b) and a_num < len(a):
        k -= a[a_num]
        a_num += 1
        continue
    elif b[b_num] <= k and a_num == len(a) and b_num < len(b):
        k -= b[b_num]
        b_num += 1
        continue
    elif a[a_num] <= k and a[a_num] <= b[b_num] and a_num < len(a):
        k -= a[a_num]
        a_num += 1
        continue
    elif b[b_num] <= k and b[b_num] < a[a_num] and b_num < len(b):
        k -= b[b_num]
        b_num += 1
        continue
    else:
        break
print(a_num + b_num)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin

# import numpy as np
from itertools import accumulate
from bisect import bisect_right

# import sys
# sys.setrecursionlimit(10**4)


def _li():
    return list(map(int, stdin.readline().split()))


def _li_():
    return list(map(lambda x: int(x) - 1, stdin.readline().split()))


def _lf():
    return list(map(float, stdin.readline().split()))


def _ls():
    return stdin.readline().split()


def _i():
    return int(stdin.readline())


def _f():
    return float(stdin.readline())


def _s():
    return stdin.readline()[:-1]


def search(cum1, cum2, iter_max, limit):
    ans = 0
    for i in range(iter_max):
        if cum1[i] > limit:
            break
        cand = bisect_right(cum2, limit - cum1[i])
        ans = max(i + 1 + cand, ans)
    return ans


N, M, K = _li()
A_list = _li()
B_list = _li()

cum_a = list(accumulate(A_list))
cum_b = list(accumulate(B_list))

if cum_a[0] < cum_b[0]:
    print(search(cum_a, cum_b, N))
else:
    print(search(cum_b, cum_a, M))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin

# import numpy as np
from itertools import accumulate
from bisect import bisect_right

# import sys
# sys.setrecursionlimit(10**4)


def _li():
    return list(map(int, stdin.readline().split()))


def _li_():
    return list(map(lambda x: int(x) - 1, stdin.readline().split()))


def _lf():
    return list(map(float, stdin.readline().split()))


def _ls():
    return stdin.readline().split()


def _i():
    return int(stdin.readline())


def _f():
    return float(stdin.readline())


def _s():
    return stdin.readline()[:-1]


def search(cum1, cum2, iter_max):
    ans = 0
    for i in range(iter_max):
        if cum1[i] > K:
            break
        cand = bisect_right(cum2, K - cum1[i])
        ans = max(i + 1 + cand, ans)
    return ans


N, M, K = _li()
A_list = _li()
B_list = _li()

cum_a = list(accumulate(A_list))
cum_b = list(accumulate(B_list))

ans = 0
if cum_a[0] < cum_b[0]:
    print(search(cum_a, cum_b, N))
else:
    print(search(cum_b, cum_a, N))

Submission status: Runtime Error

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

time = 0
nBooks = 0
iterA = 0
iterB = 0

less = min(listA[iterA], listB[iterB])
while time + less <= n:
    time = time + less
    if listA[iterA] == less:
        iterA += 1
    else:
        iterB += 1
    less = min(listA[iterA], listB[iterB])

print(time)

Submission status: Runtime Error

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

time = 0
nBooks = 0
iterA = 0
iterB = 0

less = min(listA[iterA], listB[iterB])
while time + less <= n:
    time = time + less
    if listA[iterA] == less:
        iterA += 1
    else:
        iterB += 1
    less = min(listA[iterA], listB[iterB])

Submission status: Runtime Error

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

#n,m,k = map(int,first_input.split())
#a_list = list(map(int,second_input.split()))
#b_list = list(map(int,third_input.split()))

ans = 0
amari_time = k
a_max_num = 0
b_max_num = 0
a_max_startpoint = 0
breakflg = False

#Aの最大冊数（余りがあれば、その中でBの冊数も読みに行く）
for a_item in a_list:
    amari_time = amari_time - a_item
    if (amari_time > 0):
        a_max_num = a_max_num + 1
    else:
        amari_time = amari_time + a_item
        break

for b_item in b_list:
    amari_time = amari_time - b_item
    if(amari_time > 0):
        b_max_num = b_max_num + 1
    else:
        amari_time = amari_time + b_item
        break
#とりあえず一回目の試行の合計を出す
ans = a_max_num + b_max_num
a_max_startpoint = a_max_num

#Aを一冊づつ減らしていき、Bの本を読めるだけ読んでいく
for tail_item_index in range(a_max_startpoint, -1, -1):
    amari_time = amari_time + a_list[tail_item_index]
    a_max_num = a_max_num - 1
    while (amari_time >= b_list[b_max_num]):
        amari_time = amari_time - b_list[b_max_num]
        b_max_num = b_max_num + 1
        if (len(b_list) <= b_max_num):
            breakflg = True
            break
    if breakflg:
        break
    elif (a_max_num + b_max_num > ans):
        ans = a_max_num + b_max_num
    

print(str(ans))
#print(str(amari_time))

Submission status: Runtime Error

Solution code:
from collections import deque

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

while(K > 0):

    if len(A) == 0 and len(B) == 0:
      break
    if K < A[0] and K < B[0]:
      break
    
    if len(A) == 0:
        K -= B.popleft()
        res += 1
    elif len(B) == 0:
        K -= A.popleft()
        res += 1
    elif A[-1] > B[-1]:
        K -= B.popleft()
        res += 1
    else:
        K -= A.popleft()
        res += 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()))
res = 0
ai = N-1
bi = M-1

while(K > 0):

    if len(A) == 0 and len(B) == 0:
      break
    if K < A[-1] and K < B[-1]:
      break
    
    if len(A) == 0:
        K -= B.pop()
        res += 1
    elif len(B) == 0:
        K -= A.pop()
        res += 1
    elif A[-1] > B[-1]:
        K -= B.pop()
        res += 1
    else:
        K -= A.pop()
        res += 1


print(res)

Submission status: Runtime Error

Solution code:
# C-Tsundoku

#机AにN冊
#机BにM冊
#制限時間K分

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


sum_time = 0 #読んだ本の合計時間を加算していく
sum_book = 0 #読んだ本の合計冊数を加算していく

A_len = len(A) #リストAの長さ
B_len = len(B) #リストBの長さ

Acou = 0 #リストの添え字に応じて加算
Bcou = 0 #リストの添え字に応じて加算

while (Acou < A_len - 1) and (Bcou < B_len - 1):
	if K <= sum_time:#合計時間が制限時間と同じかそれより以上の場合
		break #処理を終了
	elif A[Acou] <= B[Bcou]:
		sum_time += A[Acou] #一番上のAの本の所要時間を加算
			if K > sum_time:
				sum_book += 1 #一冊読んだので加算
				Acou += 1 #選択する本を変更=読んだ本を除外

#		print(sum_time) #経過試験
#		print(sum_book) #経過試験
#		print(Acou)	#経過試験


	elif A[Acou] > B[Bcou]:
		sum_time += B[Bcou] 
		if K > sum_time:
			sum_book += 1 #一冊読んだので加算
			Bcou += 1

#		print(sum_time) #経過試験
#		print(sum_book) #経過試験
#		print(Acou)	#経過試験




if K < sum_time:
	print(sum_book)
elif (Acou < A_len -1) and (Bcou == B_len -1):
	for i in range(Acou,A_len):
		if K <= sum_time:
			break
		else:
			sum_time += A[i]
			if K > sum_time:
				sum_book += 1 #一冊読んだので加算

#		print(sum_time) #経過試験
#		print(sum_book) #経過試験

	print(sum_book)
elif (Acou == A_len - 1) and (Bcou < B_len - 1):
	for i in range(Bcou,B_len):
		if K <= sum_time:
			break
		else:
			sum_time += B[i]
			if K > sum_time:
				sum_book += 1 #一冊読んだので加算


#		print(sum_time) #経過試験
#		print(sum_book) #経過試験

	print(sum_book)

Submission status: Runtime Error

Solution code:
# C-Tsundoku

#机AにN冊
#机BにM冊
#制限時間K分

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


sum_time = 0 #読んだ本の合計時間を加算していく
sum_book = 0 #読んだ本の合計冊数を加算していく

A_len = len(A) #リストAの長さ
B_len = len(B) #リストBの長さ

Acou = 0 #リストの添え字に応じて加算
Bcou = 0 #リストの添え字に応じて加算

while (Acou < A_len - 1) and (Bcou < B_len - 1):
	if K <= sum_time:#合計時間が制限時間と同じかそれより以上の場合
		break #処理を終了
	elif A[Acou] <= B[Bcou]:
		sum_time += A[Acou] #一番上のAの本の所要時間を加算
			if K > sum_time:
			sum_book += 1 #一冊読んだので加算
		Acou += 1 #選択する本を変更=読んだ本を除外

#		print(sum_time) #経過試験
#		print(sum_book) #経過試験
#		print(Acou)	#経過試験


	elif A[Acou] > B[Bcou]:
		sum_time += B[Bcou] 
		if K > sum_time:
			sum_book += 1 #一冊読んだので加算
		Bcou += 1

#		print(sum_time) #経過試験
#		print(sum_book) #経過試験
#		print(Acou)	#経過試験




if K < sum_time:
	print(sum_book)
elif (Acou < A_len -1) and (Bcou == B_len -1):
	for i in range(Acou,A_len):
		if K <= sum_time:
			break
		else:
			sum_time += A[i]
			if K > sum_time:
			sum_book += 1 #一冊読んだので加算

#		print(sum_time) #経過試験
#		print(sum_book) #経過試験

	print(sum_book)
elif (Acou == A_len - 1) and (Bcou < B_len - 1):
	for i in range(Bcou,B_len):
		if K <= sum_time:
			break
		else:
			sum_time += B[i]
			if K > sum_time:
			sum_book += 1 #一冊読んだので加算


#		print(sum_time) #経過試験
#		print(sum_book) #経過試験

	print(sum_book)

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 b == bnum:
    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)