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:
def read(a,b,k):
    book = 0
    i = 0
    j = 0
    while i<len(a):
        if a[i]<=b[j] and k>=a[i]:
            k-=a[i]
            i+=1
            book+=1
        elif b[j]<=a[i] and k>=b[j]:
            k-=b[j]
            j+=1
            book+=1
        else:
            break
    while j<len(b):
        if b[j]<=a[i-1] and k>=b[j]:
            k-=b[j]
            j+=1
            book+=1
        elif a[i]<=b[j] and k>=a[i]:
            k-=a[i]
            i+=1
            book+=1
        else:
            break
        
    return book
 
 
if __name__ == "__main__":
    n,m,k = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    print(read(a,b,k))

Submission status: Runtime Error

Solution code:
a,b,c=map(int,input().split())
li_a=list(map(int,input().split()))
li_b=list(map(int,input().split()))

count=0
x=0
y=0
while c>=0:
  if a!=0 and b!=0:
    c=c-min(li_a[x],li_b[y])
    if li_a[y]>=li_b[x]:
      x+=1
      a-=1
    else:
      y+=1
      b-=1
    if c<0:
      break
    count+=1

  if a!=0 and b==0:
    c=c-li_a[x]
    x+=1
    a-=1
    if c<0:
      break
    count+=1
  if a==0 and b!=0:
    y+=1
    b-=1
    c=c-li_b[y]
    if c<0:
      break
    count+=1
  if a==0 and b==0:
    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()))


result = 0

for i in range(len(a)):
    if k >= a[i]:
        k = k-a[i]
        result += 1
        if k >= b[i]:
            k = k-b[i]
            result += 1
        else:
            break
    else:
        break

for i in range(len(a), len(b)):
    if k >= b[i]:
            k = k-b[i]
            result += 1
    else:
        break

print(result)

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

time_A = list(map(int, input().split()))
time_B = list(map(int, input().split()))
max_books = 0
num_books = 0
allot_to_A = 0
allot_to_B = K

time_bankA = allot_to_A
time_bankB = allot_to_B
read_in_B = []
baf_timeB = 0

for i in range(len(time_B)):
    if time_B[i] <= time_bankB:
        time_bankB -= time_B[i]
        num_books += 1
        read_in_B.append(time_B[i])
    else:
        baf_timeB = time_bankB
if baf_timeB == 0:
    baf_timeB = K - sum(time_B)
max_books = num_books
tmp = max_books


for i in range(len(time_A)):
    dif = 1
    allot_to_A += time_A[i]
    allot_to_B -= time_A[i]
    if allot_to_B < 0:
        break
    time_to_reduce = time_A[i]
    while time_to_reduce > 0:
        if time_to_reduce <= baf_timeB:
            baf_timeB -= time_to_reduce
            break
        else:
            baf_timeB += read_in_B[-1]
            dif -= 1
            del read_in_B[-1]
    tmp += dif
    max_books = max(tmp, max_books)

print(max_books)

Submission status: Runtime Error

Solution code:
str_list = [input() for _ in range(3)]
n=int(str_list[0].split(" ")[0])
m=int(str_list[0].split(" ")[1])
k=int(str_list[0].split(" ")[2])
list1=str_list[1].split(" ")
list2=str_list[2].split(" ")
time=0
count=0
a=0
b=0

for i in range(0, int(len(list1)+len(list2))):
    if int(list1[0])>k and int(list2[0])>k:
        break
    if a<int(len(list1)) and b<int(len(list2)):
        if int(list1[a])<int(list2[b]):
            time+=int(list1[a])
            a+=1
        elif int(list1[a])>int(list2[b]):
            time+=int(list2[b])
            b+=1
        else:
            hoge=1
            if a+hoge<int(len(list1)) and b+hoge<int(len(list2)):
                for l in range(1, int(len(list1)+len(list2))):
                    if int(list1[a+hoge])<int(list2[b+hoge]):
                        time+=int(list1[a])
                        a+=1
                        break
                    elif int(list1[a+hoge])>int(list2[b+hoge]):
                        time+=int(list2[b])
                        b+=1
                        break
                    else:
                        hoge+=1
            elif a+hoge==int(len(list1)):
                time+=int(list2[b])
                b+=1
            elif b+hoge==int(len(list2)):
                time+=int(list1[a])
                b+=1
    elif a==int(len(list1)):
        time+=int(list2[b])
        b+=1
    elif b==int(len(list2)):
        time+=int(list1[a])
        a+=1
    if time>k:
        break
    count+=1

print(count)

Submission status: Runtime Error

Solution code:
N, M, K = map(int, input().split())
2 A = list(map(int, input().split()))
3 B = list(map(int, input().split()))
4
5 a, b = [0], [0]
6 for i in range(N):
7 a.append(a[i] + A[i])
8 for i in range(M):
9 b.append(b[i] + B[i])
10
11 ans, j = 0, M
12 for i in range(N + 1):
13 if a[i] > K:
14 break
15 while b[j] > K - a[i]:
16 j -= 1
17 ans = max(ans, i + j)
18 print(ans)

Submission status: Runtime Error

Solution code:
str_list = [input() for _ in range(3)]
n=int(str_list[0].split(" ")[0])
m=int(str_list[0].split(" ")[1])
k=int(str_list[0].split(" ")[2])
list1=str_list[1].split(" ")
list2=str_list[2].split(" ")
time=0
count=0
a=0
b=0

for i in range(0, int(len(list1)+len(list2))):
    if int(list1[0])>k and int(list2[0])>k:
        break
    if a<int(len(list1)) and b<int(len(list2)):
        if int(list1[a])<int(list2[b]):
            time+=int(list1[a])
            a+=1
        elif int(list1[a])>int(list2[b]):
            time+=int(list2[b])
            b+=1
        else:
            hoge=1
            if a+hoge<int(len(list1)) and b+hoge<int(len(list2)):
                for l in range(1, int(len(list1)+len(list2))):
                    if int(list1[a+hoge])<int(list2[b+hoge]):
                        time+=int(list1[a])
                        a+=1
                        break
                    elif int(list1[a+hoge])>int(list2[b+hoge]):
                        time+=int(list2[b])
                        b+=1
                        break
                    else:
                        hoge+=1
            elif a+hoge==int(len(list1)):
                time+=int(list2[b])
                b+=1
            elif b+hoge==int(len(list2)):
                time+=int(list1[a])
                b+=1
    elif a==int(len(list1)):
        time+=int(list2[b])
        b+=1
    elif b==int(len(list2)):
        time+=int(list1[a])
        a+=1
    count+=1
    if time>=k:
        break

print(count)

Submission status: Runtime Error

Solution code:
import itertools
N,M,K = map(int,input().split())
A = [0]+list(map(int,input().split()))
B = [0]+list(map(int,input().split()))
SA = list(itertools.accumulate(A))
SB = list(itertools.accumulate(B))
ans = 0
j = len(B)-1
for i in range(len(SA)):
    while(pt>=0):
        if SA[i] + SB[j] <= K:
            ans = max(ans,i+j)
            break
        j-=1
print (ans)

Submission status: Runtime Error

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

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 = 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 min(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)
if ans==10**10:
    print(0)
else:
    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())))

b_li = np.array([0] * k)
bsum = 0
for i in range(m):
  bsum += b[i]
  b_li[bsum:] += 1

#print(b_li)

ans = 0
asum = 0
for i in range(n):
  asum += a[i]
  if asum <= k and b_li[k-asum] + i+1 > ans:
    ans = b_li[k-asum] + i+1

print(ans)

Submission status: Runtime Error

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

A = [0]
B = [0]

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

TIME = 0
ans = 0

Ta = 0
Tb = 0

for i in range(N + 1):
    if Ta > K:
        continue
    Ta += A[i]

    if i == 0:
        Tb = 0
        for j in range(M+1):
            Tb += B[j]
            if (Ta + Tb) > K:
                break
            else:
                TB = Tb
                ans = max(ans, i + j)
    else:
        if (Ta + Tb) > K:            
            while (Ta + Tb) > K:
                j -= 1
                Tb -= B[j]
        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()))

# print(N,M,K)
# print(A)
# print(B)
sum_on = 0
count = 0
i = 0
if K < A[0]:
    pass
else:
    while True:
        if sum_on < K:
            if len(A) == 0:
                sum_on += B.pop(i)
                count += 1
            else:
                sum_on += A.pop(i)
                count += 1
                if A[i] > B[i]:
                    sum_on += B.pop(i)
                    count += 1

                else:
                    sum_on += A.pop(i)
                count += 1
        else:
            break
        break
print(count)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 27 21:07:13 2020

@author: naoki
"""
from collections import deque 

N,M,K = map(int,input().split())
A = deque(map(int,input().split()))
B = deque(map(int,input().split()))
print(A)
print(B)
time = 0 
count = 0 

while time <= K:
    count += 1
    if  len(A) >=1 and len(B)>=1:
        if A[0] < B[0]:
            time += A[0]
            A.popleft()
        else:
            time += B[0]
            B.popleft()
    elif len(A) == 0:
        time += B[0]
        B.popleft()
    else:
        time += A[0]
        A.popleft()
    print(time)
    print(A)
    print(B)
if count >= 1:    
    print(count-1)
else:
    print(0)

Submission status: Runtime Error

Solution code:
str_list = [input() for _ in range(3)]
n=int(str_list[0].split(" ")[0])
m=int(str_list[0].split(" ")[1])
k=int(str_list[0].split(" ")[2])
list1=str_list[1].split(" ")
list2=str_list[2].split(" ")
time=0
count=0
a=0
b=0

for i in range(0, int(len(list1)+len(list2))):
    if int(list1[0])>k and int(list2[0])>k:
        break
    if a<int(len(list1)) and b<int(len(list2)):
        if int(list1[a])<int(list2[b]):
            time+=int(list1[a])
            a+=1
        elif int(list1[a])>int(list2[b]):
            time+=int(list2[b])
            b+=1
        else:
            hoge=1
            if a+hoge<int(len(list1)) and b+hoge<int(len(list2)):
                for l in range(1, int(len(list1)+len(list2))):
                    if int(list1[a+hoge])<int(list2[b+hoge]):
                        time+=int(list1[a])
                        a+=1
                        break
                    elif int(list1[a+hoge])>int(list2[b+hoge]):
                        time+=int(list2[b])
                        b+=1
                        break
                    else:
                        hoge+=1
            elif a+hoge==int(len(list1)):
                time+=int(list2[b])
                b+=1
            elif b+hoge==int(len(list2)):
                time+=int(list1[a])
                b+=1
    elif a==int(len(list1)):
        time+=int(list2[b])
        b+=1
    elif b==int(len(list2)):
        time+=int(list1[a])
        a+=1
    if time>=k:
        break
    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()))

print(a)
print(b)

read = 0
time_ = 0
ai = 0
bi = 0

max_read = 0

def readbook(time, read, ai, bi, isa):
    
    if isa:
        if ai < n:
            time += a[ai]
        else:
            return
    else:
        if bi < m:
            time += b[bi]
        else:
            return
    if time > k:
        return
    else:
        # readable
        read += 1
        global max_read
        if read > max_read:
            max_read = read

        readbook(time, read, ai + 1, bi, True)
        readbook(time, read, ai, bi + 1, False)


readbook(time_, read, ai, bi, True)
read = 0
time_ = 0
ai = 0
bi = 0
readbook(time_, read, ai, bi, False)

if max_read !=0:
    max_read += 1
print(max_read)

Submission status: Runtime Error

Solution code:
from sys import exit
from collections import deque
# import copy
# import numpy as np
# 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())))

cnt = 0

while k >= a[0] or k >= b[0]:
    if a[0] < b[0]:
        k -= a.popleft()
        cnt += 1

    elif a[0] > b[0]:
        k -= b.popleft()
        cnt += 1

    else:
        for i in range(1, min(len(a), len(b))+1):
            if a[i] < b[i]:
                for t in range(0, i+1):
                    k -= a.popleft()
                    cnt += 1
                    if k < a[0]:
                        break
                break
            elif a[i] > b[i]:
                for t in range(0, i+1):
                    k -= b.popleft()
                    cnt += 1
                    if k < b[0]:
                        break
                break
        else:
            if len(a) > len(b):
                for i in range(len(a)):
                    k -= a.popleft()
                    if k < a[0]:
                        break
            else:
                for i in range(len(b)):
                    k -= b.popleft()
                    cnt += 1
                    if k < b[0]:
                        break
    if a == deque([]):
        for i in range(len(b)):
            if k < b[0]:
                break
            k -= b.popleft()
            cnt += 1
        break
    if b == deque([]):
        for i in range(len(a)):
            if k < a[0]:
                break
            k -= a.popleft()
            cnt += 1
        break
print(cnt)

Submission status: Runtime Error

Solution code:
from collections import dequeue


N, M, K = map(int, input().split())
listA = [int(i) for i in input().split()]
listB = [int(i) for i in input().split()]
queueA = dequeue(listA)
queueB = dequeue(listB)

candidates = [0,]
while True:
  if listA[0] < listB[0]:
    if sum(candidates) + listA[0] <= K:
    	candidates.append(queueA.popleft())
    elif sum(candidates) + listB[0] <= K:
        candidates.append(queueB.popleft())
    else:
      break
  else:
    if sum(candidates) + listB[0] <= K:
	    candidates.append(queueB.popleft())
    elif sum(candidates) + listA[0] <= K:
      candidates.append(queueA.popleft())
    else:
      break

print(len(candidates)-1)

Submission status: Runtime Error

Solution code:
import sys

input = lambda: sys.stdin.readline().rstrip()

n, m, k = map(int, input().split())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))

cnt = 0
if A[0] < B[0] and A[0] <= k:
    cnt += 1
    k -= A[0]

idx_a = 1
idx_b = 0

while k > 0:
    if B[idx_b] > A[idx_a]:
        k -= A[idx_a]
        if k >= 0: cnt += 1
        if idx_a < n - 1: idx_a += 1

    if B[idx_b] < A[idx_a]:
        k -= B[idx_b]
        if k >= 0: cnt += 1
        if idx_b < m - 1: idx_b += 1

    if B[idx_b] == A[idx_a]:
        k -= A[idx_a]
        if k >= 0: cnt += 1
        if idx_a < n - 1: idx_a += 1
        
        k -= B[idx_b]
        if k >= 0: cnt += 1
        if idx_b < m - 1: idx_b += 1

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()))
ans=0
ai=0
bi=0
for i in range(n+m):
  ans+=1
  if n-ai==0:
    k-=b[bi]
    bi+=1
  elif m-bi==0:
    k-=a[ai]
    ai+=1
  elif a[ai]>b[bi]:
    k-=b[bi]
    bi+=1
  elif b[bi]>a[ai]:
    k-=a[ai]
    ai+=1
  else:
    if n==ai+2:
      k-=b[bi]
      bi+=1
    elif m==bi+2:
      k-=a[ai]
      ai+=1
    elif a[ai+1]>=b[bi+1]:
      k-=b[bi]
      bi+=1
    elif a[ai+1]<b[bi+1]:
      k-=a[ai]
      ai+=1
  if k<0:
    ans-=1
    break
print(ans)

Submission status: Runtime Error

Solution code:
str_list = [input() for _ in range(3)]
n=int(str_list[0].split(" ")[0])
m=int(str_list[0].split(" ")[1])
k=int(str_list[0].split(" ")[2])
list1=str_list[1].split(" ")
list2=str_list[2].split(" ")
time=0
count=0
a=0
b=0

print(0, 0)
for i in range(0, int(len(list1)+len(list2))):
    if int(list1[0])>k and int(list2[0])>k:
        break
    if a<int(len(list1)) and b<int(len(list2)):
        if int(list1[a])<int(list2[b]):
            time+=int(list1[a])
            a+=1
        elif int(list1[a])>int(list2[b]):
            time+=int(list2[b])
            b+=1
        else:
            hoge=1
            if a+hoge<int(len(list1)) and b+hoge<int(len(list2)):
                for l in range(1, int(len(list1)+len(list2))):
                    if int(list1[a+hoge])<int(list2[b+hoge]):
                        time+=int(list1[a])
                        a+=1
                        break
                    elif int(list1[a+hoge])>int(list2[b+hoge]):
                        time+=int(list2[b])
                        b+=1
                        break
                    else:
                        hoge+=1
            elif a+hoge==int(len(list1)):
                time+=int(list2[b])
                b+=1
            elif b+hoge==int(len(list2)):
                time+=int(list1[a])
                b+=1
    elif a==int(len(list1)):
        time+=int(list2[b])
        b+=1
    elif b==int(len(list2)):
        time+=int(list1[a])
        a+=1
    if time>=k:
        break
    count+=1

print(count)

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())))
dp = [0] * (len(A)+len(B)+1)
i = j = 0
for idx in range(len(dp)):
    if i >= len(A) and j >= len(B):
        print(i+j)
        exit()
    if i >= len(A):
        dp[idx+1] = dp[idx] + B[j]
        j += 1
    elif j >= len(B):
        dp[idx+1] = dp[idx] + A[j]
    elif dp[idx] + A[i] < dp[idx] + B[j]:
        dp[idx+1] = dp[idx] + A[i]
        i += 1
    else:
        dp[idx+1] = dp[idx] + B[j]
        j += 1
    if dp[idx+1] > K:
        break
print(i+j-1)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
from itertools import accumulate

N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
Acc = list(accumulate(A))
Bcc = list(accumulate(B))
a = N-1
b = M-1
ans = 0
for n,i in enumerate(Acc):
    if i > K:
        a = n-1
        break
for n,i in enumerate(Bcc):
    if i > K:
        b = n-1
        break
if a > b:
    K -= Acc[a]
    b = 0
    for i in B:
        if i <= K:
            K -= i
            b += 1
        elif i < A[a]:
            K += A[a]-i
            a -= 1
            b += 1
        else:
            break
else:
    K -= Bcc[b]
    a = 0
    for i in A:
        if i <= K:
            K -= i
            b += 1
        elif i < B[b]:
            K += B[b] - i
            b -= 1
            a += 1
        else:
            break
a = a+1 if a else a
b = b+1 if b else b
print(a+b)

Submission status: Runtime Error

Solution code:
N,M,K=map(int, input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

a=[N, 0]
b=[M, 0]
rt=ai=bi=c=0

while True:
  if ai==N and bi==M:
    break
  if ai<N and A[ai] < B[bi]:
    r = A[ai]
    ai+=1
  else:
    r = B[bi]
    bi+=1

  if rt + r <= K:
    rt += r
    c += 1
    continue
  break
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()))

ans =0
sum =0
Acon =0
Bcon =0
for i in range(N):
    for j in range(M):
        if A[i] >=1000000000 or B[i]>=1000000000:
            break
        if A[i] <= B[j]:
            ans +=A[i]
            sum +=1
            Acon +=1
            break
        elif A[i] >= B[j] and Bcon<=j:
            ans +=B[j]
            sum +=1
            Bcon +=1

if Acon ==N and K-ans >= B[Bcon]:
    for i in range(Bcon,M-Bcon+1):
        if B[i]>=1000000000:
            break
        ans += B[i]
        sum +=1
elif Bcon ==M and K-ans >= A[Acon]:
    for i in range(Acon,N-Acon+1):
        if A[i]>=1000000000:
            break
        ans += A[i]
        sum +=1

print(sum)

Submission status: Runtime Error

Solution code:
# C-Tsundoku


#N冊、M冊、時間K
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

#Aの机の現在の1番上の本の時間とBの机の一番上の本の時間を比較して小さい本を選択して
#本、時間をそれぞれ累積していき、本を削除していく。
#これを繰り返して時間Kより大きい場合になったときに処理を終了させる
#この時、本はカウントしない


time = 0
len_min = Min(len(a),len(b))
aco = 0
bco = 0
book = 0

while k > time:
	for i in range(len_min):
		if (aco - 1) == len(a) or (bco - 1) ==len(b):
			if (aco - 1) == len(a) and (bco - 1) ==len(b):
				break
			elif (aco - 1) != len(a) and (bco - 1) ==len(b):
				book += 1
				time += a[aco]
				aco += 1
			else:
				book += 1
				time += b[bco]
				bco += 1
		elif a[aco] <= b[bco]:
			book += 1
			time += a[aco]
			aco += 1
		elif a[aco] > b[bco]:
			book += 1
			time += b[bco]
			bco += 1

Submission status: Runtime Error

Solution code:
str_list = [input() for _ in range(3)]
n=int(str_list[0].split(" ")[0])
m=int(str_list[0].split(" ")[1])
k=int(str_list[0].split(" ")[2])
list1=str_list[1].split(" ")
list2=str_list[2].split(" ")
time=0
count=0
a=0
b=0

print(0, 0)
for i in range(0, int(len(list1)+len(list2))):
    if int(list1[0])>k and int(list2[0])>k:
        break
    if a<int(len(list1)) and b<int(len(list2)):
        if int(list1[a])<int(list2[b]):
            time+=int(list1[a])
            a+=1
        elif int(list1[a])>int(list2[b]):
            time+=int(list2[b])
            b+=1
        else:
            hoge=1
            if a+hoge<int(len(list1)) and b+hoge<int(len(list2)):
                for l in range(1, int(len(list1)+len(list2))):
                    if int(list1[a+hoge])<int(list2[b+hoge]):
                        time+=int(list1[a])
                        a+=1
                        break
                    elif int(list1[a+hoge])>int(list2[b+hoge]):
                        time+=int(list2[b])
                        b+=1
                        break
                    else:
                        hoge+=1
            elif a+hoge==int(len(list1)):
                time+=int(list2[b])
                b+=1
            elif b+hoge==int(len(list2)):
                time+=int(list1[a])
                b+=1
    elif a==int(len(list1)):
        time+=int(list2[b])
        b+=1
    elif b==int(len(list2)):
        time+=int(list1[a])
        a+=1
    print(a, b)
    print(time)
    if time>=k:
        break
    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()))
sum_a={}
tmp=0
for i in range(len(a)):
    tmp+=a[i]
    if tmp>k:
        break
    sum_a.update({i+1:tmp})
if len(sum_a)==0:
    sum_a.update({0:0})
    
sum_b={}
tmp=0
for i in range(len(b)):
    tmp+=b[i]
    if tmp>k:
        break
    sum_b.update({i+1:tmp})
if len(sum_b)==0:
    sum_b.update({0:0})

c_a = max(sum_a.keys())
c_b = max(sum_b.keys())
tmp = sum_a[c_a]+sum_b[c_b]
if tmp<=k:
    print(c_a+c_b)
else:
    for i in range(max(c_a,c_b)+1):
        if sum_a[c_a]>=sum_b[c_b]:
            c_a-=1
        else:
            c_b-=1
        if sum_a[c_a]+sum_b[c_b]<=k:
            print(c_a+c_b)
            break

Submission status: Runtime Error

Solution code:
N, M, K = [int(x) for x in input().split()]
tempA = [int(x) for x in input().split()]
tempB = [int(x) for x in input().split()]
A = [0]
B = [0]
s = 0
t = 0
for a in tempA:
    s += a
    A.append(s)
for b in tempB:
    t += b
    B.append(t)
lst = []
for i in range(N+1):
    for j in range(M+1):
        if K >= A[i] + B[j]:
            ans = max(ans, i+j)
        else:
            break
print(ans)

Submission status: Runtime Error

Solution code:
X=list(map(int, input().split()))

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

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

x= 0
y=0
sum =0
count=0

while True:

    if A[x] > B[y] and x < N:
        x=x+1
        sum = sum+A[x]
    if B[y] > A[x] and y < M:  
        y=y+1
        sum = sum+B[y]
    
    count = count+1
    if sum>= K:
        break
    
print(count)

Submission status: Runtime Error

Solution code:
n = 0
m = 0
k = 0
i = 0
multi = 1
x = input() 
while x[i]!=' ':
  n += (ord(x[i]) - 48) * multi
  multi *= 10
  i+=1
i+=1 
multi = 1
while x[i]!=' ':
  m += (ord(x[i]) - 48) * multi
  multi *= 10
  i+=1
i+=1 
multi = 1
while True:
  k += (ord(x[i]) - 48) * multi
  multi *= 10
  i+=1
  if i == len(x):
    break

x = input()
idid = 1
a = [0,0]
for newLoopVar in range(len(x)):
  i += 1 
  multi = 1
  while True:
    if i == len(x):
      break
    a[idid] += (ord(x[i]) - 48) * multi
    multi *= 10
    i+=1
  idid += 1

x = input()
idid = 1
b = [0,0]
for newLoopVar in range(len(x)):
  i += 1 
  multi = 1
  while x[i]!=' ':
    if idid == len(b):
      break
    b[idid] += (ord(x[i]) - 48) * multi
    multi *= 10
    i+=1
  idid += 1

maxTime = k 
totalNumBooks = n + k
booksRead = 0

while True:
  if a >= b and a[1] < maxTime:
    maxTime -= a
    a.remove(a[1])
    booksRead += 1
  elif b>a and b[1]<maxTime:
    maxTime -= b
    b.remove(b[1])
    booksRead += 1
  else:
    break



print(booksRead)

Submission status: Runtime Error

Solution code:
from pulp import *
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
res_a = [sum(a[:i+1]) for i in range(len(a))]
res_b = [sum(b[:i+1]) for i in range(len(b))]
a_value = [i for i in range(1,n+1)]
b_value = [i for i in range(1,m+1)]

w = res_a+res_b
v = a_value+b_value

W =k
r = range(len(w))

# 数理モデル
ma = LpProblem(sense=LpMaximize)

# 変数
x = [LpVariable('x%d'%i, cat=LpBinary) for i in r]

# 目的関数
ma += lpDot(v, x)

# 制約
ma += lpDot(w, x) 
W =ma.solve() 
print(value(ma.objective))

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

read = 0

while K - A[0] >= 0 or K - B[0] >= 0:
    if N > 0 and M > 0:
        if A[0] < B[0]:
            N -= 1
            read += 1
            K -= pop(A[0])
        elif A[0] > B[0]:
            M -= 1
            read += 1
            K -= pop(B[0])
        else:
            i2 = 0
            j2 = 0
            while A[i2] == B[j2]:
                if A[i2] < B[j2]:
                   N -= 1
                   read += 1
                   K -= pop(A[0])
                   break
                elif A[i2] > B[j2]:
                   M -= 1
                   read += 1
                   K -= pop(B[0])
                   break
                else:
                   i2 += 1
                   j2 += 1
    elif N <= 0 and M > 0:
        M -= 1
        read += 1
        K -= pop(B[0])
        j += 1
    elif N > 0 and M <= 0:
        N -= 1
        read += 1
        K -= pop(A[0])
        i += 1
    else:
        break

print(read)