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:
import sys
import functools
from collections import deque

readline = sys.stdin.buffer.readline
n, m, k = map(int, readline().split())
a = list(map(int, readline().split()))
b = list(map(int, readline().split()))

a_len = len(a)
b_len = len(b)


ans = [0, 0, 0]

L = []
d = deque()
d.append((0, 0, 0))
while d:
    a_readed, b_readed, t = d.popleft()
    if not (a_len > a_readed and t + a[a_readed] < k) and not (b_len > b_readed and t + b[b_readed] < k):
        L.append(a_readed + b_readed)
    else:
        if a_len > a_readed and t + a[a_readed] < k:
            d.append((a_readed + 1, b_readed, t + a[a_readed]))
        if b_len > b_readed and t + b[b_readed] < k:
            d.append((a_readed, b_readed + 1, t + b[a_readed]))

ans = max(L)
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

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

a = input().split()
np_a=np.array(a, dtype='int64')
b = input().split()
np_b=np.array(b, dtype='int64')

ia=0
ib=0
time=0
hon=n+m
for i in range(0,n+m):
  if (ia == n): 
    time+=np_b[ib]
    ib+=1
  elif (ib == m): 
    time+=np_a[ia] 
    ia+=1
  elif (ia < n or ib < m): 
    if (np_a[ia] < np_b[ib]):
      time+=np_a[ia]
      ia+=1
    if (np_a[ia] > np_b[ib]):
      time+=np_b[ib]
      ib+=1
    if (np_a[ia] = np_b[ib] and np_a[ia] < np_b[ib]):
      time+=np_a[ia]
      ia+=1
    if (np_a[ia] = np_b[ib] and np_a[ia] > np_b[ib]):
      time+=np_b[ib]
      ib+=1
    
  if (time > k): 
    hon=i
    break

print (hon)

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, j, ans = 0, 0, 0
while K > 0:
    if i == N and j == M:
        break
    elif i == N:
        K -= B[j]
        j += 1
    elif j == M:
        K -= A[i]
        i += 1
    if A[i] == B[j]:
        k, clear = 1, False
        while i+k < N and j+k < N:
            if A[i+k] == B[j+k]:
                k += 1
            elif A[i+k] < B[j+k]:
                K -= A[i]
                i += 1
                clear = True               
                break
            elif A[i+k] < B[j+k]:
                K -= B[j]
                j += 1
                clear = True               
                break
        if not clear:
            K -= A[i]
            i += 1
    elif A[i] < B[j]:
        K -= A[i]
        i += 1
    else:
        K -= B[j]
        j += 1
    ans += 1

if K < 0:
    ans -= 1
print(ans)

Submission status: Runtime Error

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

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

a = sum(A)
b = sum(B)
if a <K:
    m = len(A)
    t = a
    for j in range(M):
        t += B[j]
        if t > K:
            break
        #print(total)
        mi += 1
    m = max(m, mi)

elif b<K:
    m = len(B)
    t = b
    for j in range(N):
        t += B[j]
        if t > K:
            break
        #print(total)
        mi += 1
    m = max(m, mi)

else:
    m = 0
    total = 0
    for i in range(1, N+1):
        total += A[i-1]
        t = total
        if total > K:
            break
        mi = i
        for j in range(M):
            t += B[j]
            if t > K:
                break
            #print(total)
            mi += 1

        m = max(m, mi)


print(m)

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 += 2
        if idx_a < n - 1: idx_a += 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()))

ai=0
bi=0
time=0

def equalpat(A,B,N,M):
  if A>N:return False
  elif B>M:return True
  elif a[A]>b[B]:return True
  elif a[A]<b[B]:return False
  
  equalpat(A+1,B+1,N,M)


while ai < n and bi < m:
  if a[ai]<b[bi]:time+=a[ai];ai+=1
  elif a[ai]>b[bi] :time+=b[bi];bi+=1
  else:
    result = equalpat(ai,bi,n,m)
    if result == True:time+=b[bi] ;bi+=1
    else:time+=a[ai]; ai+=1

  if time >= k:break
    
if n > m:
  while ai < n:
    time+=a[ai];ai+=1
    if time >= k:break

if n < m:
  while bi < m:
    time+=b[bi];bi+=1
    if time >= k:break
      
print(ai+bi)

Submission status: Runtime Error

Solution code:
import os
import sys
from collections import defaultdict, Counter, deque
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy

def main():
    
    n,m,k = map(int, input().split())
    n_list = list(map(int, input().split()))
    m_list = list(map(int, input().split()))
    i,j,count = 0,0,0

    while(k>=0):

        if count == n+m:
            break

        if i <= n and j <= m:

            if n_list[i] < m_list[j]:
                k -= n_list[i]
                i += 1
            else:
                k -= m_list[j]
                j += 1
              
            if k < 0:
                break
            else:
                count += 1

        else:
            if i > n:
                if j > m:
                    break
                k -= m_list[j]
                j += 1

            elif j > m:
                if i > n:
                    break
                k -= n_list[i]
                i += 1

            if k < 0:
                break
            else:
                count += 1

    print(count)



            

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()))
t = 0
c = 0
if sum(a) + sum(b) <= k:
    print(n+m)
    quit()
for i in range(min(n, m)-1):
    if t + a[i]> k:
        print(c)
        quit()
    t += a[i]
    c += 1
    if t + b[i]> k:
        print(c)
        quit()
    t += b[i]
    c += 1
    
if t < k:
    if max(n, m) == n:
        d = a
    else:
        d = b
    for i in range (len(e)-1, len(d)-1):
        if t + d[i] > k:
            print(c)
            quit()
        t += d[i]
        c += 1
    print(c)
else:
    print(c)

Submission status: Runtime Error

Solution code:
from collections import deque

N,M,K = map(int,input().split())
Ali = list(map(int,input().split()))
Bli = list(map(int,input().split()))

r = 0
s = 0
t = 0

for i in range(N):
  if Ali[i] <= K-t:
    r += 1
    t += Ali[i]
  else:
    break
    
for i in range(M):
  if Bli[i] <= K-t:
    r += 1
    t += Bli[i]
  else:
    break
    
t = 0
for i in range(M):
  if Bli[i] <= K-t:
    s += 1
    t += Bli[i]
  else:
    break
    
for i in range(N):
  if Ali[i] <= K-t:
    s += 1
    t += Ali[i]
  else:
    break
    
t = 0
p = 0
q = 0
o = 0
while True:
  if Ali[p] < Bli[q]:
    if Ali[p] <= K-t:
      o += 1
      p += 1
      t += Ali[p]
    else:
      break
  else:
    if Bli[q] <= K-t:
      o += 1
      q += 1
      t += Ali[q]
    else:
      break
    
    
print(max(r,s,o))

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()))
#N = N-1
#M = M -1

def f(i,j,time):
  if i >= N or j >= M:
    return 0
  else:
    timeA = A[i] + time
    timeB = B[j] + time
    if timeA > K and timeB > K:
      return 0
    elif timeA > K and timeB <= K:
      return 1 + f(i, j+1, timeB)
    elif timeA <= K and timeB > K:
      return 1 + f(i+1, j, timeA)
    else:
      countA = 1 + f(i+1, j, timeA)
      countB = 1 + f(i, j+1, timeB)
      #print("cA "+str(countA))
      #print("cB "+str(countB))
      #print("tA "+str(timeA))
      #print("tB "+str(timeB))
      return max(countA, countB)

ans = f(0, 0, 0)
print(ans)

Submission status: Runtime Error

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

for i in 

a.remove(min(a))

c=list()

K=min(a)
while k>K:
    
        c.append(min(b))
        b.remove(min(b))
        K += min(b)

        if k>K:
           c.append(min(a))
           a.remove(min(a))
           K += min(a)

    print(len(c))

Submission status: Runtime Error

Solution code:

import bisect
import numpy

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

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

left_max = bisect.bisect_left(cost_a, k)
right_max = bisect.bisect_left(cost_b, k)

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

Submission status: Runtime Error

Solution code:
n, M, k = map(int,input().split())
a_l = list(map(int,input().split()))
b_l = list(map(int,input().split()))
read_a = [0]*n
read_b = [0]*M
time = 0
ans = 0
memo = 0
for j in range(n):
    if time + a_l[j] <= k:
        time += a_l[j]
        read_a[j] = 1
        memo = j
        ans = j+1
    else:
        break

kotae = [ans]


def dfs(i,a,t,m):
    global kotae
    if i < M:
        if b_l[i] + t <= k:
            tt = t + b_l[i]
            aa = a + 1
            kotae.append(aa)
            ii = i+1
            mm = m
            #print(aa)
            dfs(ii,aa,tt,mm)
            
        else:
            if m < 0:
                continue
            tt = t - a_l[m]
            mm = m - 1
            aa = a - 1
            ii = i
            #print(aa)
            dfs(ii,aa,tt,mm)
            #print(aa)


dfs(0,ans,time,memo)


print(max(kotae))

Submission status: Runtime Error

Solution code:
N,M,K = [int(a) for a in input().split()]
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
c = m = i = j = 0
tmp = []
while m <= K:
    if i >= N:
        if j >= M: break
        elif m + B[j] <= K:
            c += 1
            m += B[j]
            j += 1
        else: break
    else:
        if j >= M:
            if m + A[i] <= K:
                c += 1
                m += A[i]
                i += 1
            else: break
        else:
            if A[i] < B[j]:
                if m + A[i] <= K:
                    c += 1
                    m += A[i]
                    i += 1
                else: break
            elif A[i] > B[j]:
                if m + B[j] <= K:
                    c += 1
                    m += B[j]
                    j += 1
                else: break
            elif A[i] == B[j]:
                if m + A[i]*2 <= K:
                    i += 1
                	j += 1
                	m += A[i]*2
                    c += 2
                elif m + A[i] <= K:
                    c += 1
                    break
                else: break
            else: break
print(c)

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=0
b=0
ans=0
count=0
time=0
A1=list()
A1.append(0)
B1=list()
B1.append(0)
mA=0
mB=0
flag=0
if A[0]==1000000000 and B[0]==1000000000:
    flag=-3
    ans=0
if A[0]==1000000000:
    flag=-1
    ans=0
    memo=0
    for i in range(len(B)):
        memo+=B[i]
        if memo<=K:
            ans+=1
        else:
            break
if B[0]==1000000000:
    flag=-2
    ans=0
    memo=0
    for i in range(len(A)):
        memo+=A[i]
        if memo<=K:
            ans+=1
        else:
            break
for i in range(len(A)):
    mA+=A[i]
    if mA<1000000000:
        A1.append(mA)
    else:
        break
for i in range(len(B)):
    mB+=B[i]
    if mB<1000000000:
        B1.append(mB)
    else:
        break   
Ak=len(A1)-1
Bk=len(B1)-1

count=Ak+Bk
t=0
f=0
if flag==0:
    while True:
        for i in range(f+1):
            if A1[Ak-i]+B1[count-(Ak-i)]<=K:
                ans=count
                t=1
                break
        
        if t==1:
            break
        count-=1
        if count==0:
            ans=0
            break
        f+=1
        if Ak-f==0:
            break

print(ans)

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())))
sum = 0
count = 0
while True:
    if len(A) != 0 and len(B) != 0:
        if len(A) == 0 and B[0]+sum <= K:
            sum += B.popleft()
            count += 1
        elif len(B) == 0 and A[0]+sum <= K:
            sum += A.popleft()
            count += 1
        else
            elif A[0] < B[0] and A[0]+sum <= K:
                sum += A.popleft()
                count += 1
            elif A[0] > B[0] and B[0]+sum <= K:
                sum += B.popleft()
                count += 1
            else:
                break
    else:
        break

print(count)

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:
def resolve():
    n, m ,k= map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    a.append(10**9+1)
    b.append(10**9+1)
    ans=[]
    def f(i,j,p,ansk):

        if a[i] > p and b[j]>p:
            ans.append(ansk)

        if a[i]<=p:
            f(i+1,j,p-a[i],ansk+1)

        if b[j]<=p:
            f(i,j+1,p-b[j],ansk+1)
    f(0,0,k,0)
    if len(ans)==0:
        print(0)
    else:
        print(max(ans))
resolve()

Submission status: Runtime Error

Solution code:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list()
a=0
b=0
for i in range(N+M):
  if a+1<=N and b+1<=M and A[a]<B[b]:
    C.append(A[a])
    a+=1
  elif a+1<=N and b+1<=M and A[a]>B[b]:
    C.append(B[b])
    b+=1
  elif  a+1<=N and b+1<=M and A[a]==B[b]:
    if a+2==N:
      C.append(B[b])
      b+=1
    elif b+2==N:
      C.append(A[a])
      a+=1
    elif A[a+1]<B[b+1]:
      C.append(A[a])
      a+=1
    else:
      C.append(B[b])
      b+=1
  elif a==N:
    C.append(B[b])
    b+=1
  elif b==M:
    C.append(A[a])
    a+=1
import numpy as np
L=np.array(C).cumsum()
print(len(L[L <= K]))

Submission status: Runtime Error

Solution code:
N,M,K = map(int,input().split())
A_time = list(map(int,input().split()))
B_time = list(map(int,input().split()))
all_time = 0
a_t = A_time.pop(0)
b_t = B_time.pop(0)
count = 1
while all_time < K:
    if a_t <= b_t:
        all_time = all_time + a_t
        if count == 1 and all_time > K:
            count = -1
            break
        a_t = A_time.pop(0)
        count +=1
    else:
        all_time = all_time + b_t
        if count == 1 and all_time > K:
            count = -1
            break
        b_t = B_time.pop()
        count +=1
    if len(A_time)==0 or len(B_time)==0:
        break
        
if all_time > K:
    print(count-1)
elif count == -1:
    print(0)
else:
    if len(A_time)==0:
        while all_time > K:
            all_time = all_time + b_t
            count += 1
            b_t = B_time.pop(0)
        print(count - 1)
    else:
        while all_time > K:
            all_time = all_time + a_t
            count += 1
            b_t = A_time.pop(0)
        print(count - 1)

Submission status: Runtime Error

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

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

a = sum(A)
b = sum(B)
if a <K:
    m = len(A)
    total = a
    for j in range(M):
        t += B[j]
        if t > K:
            break
        #print(total)
        mi += 1
    m = max(m, mi)

elif b<K:
    m = len(B)
    total = b
    for j in range(N):
        t += B[j]
        if t > K:
            break
        #print(total)
        mi += 1
    m = max(m, mi)

else:
    m = 0
    total = 0
    for i in range(1, N+1):
        total += A[i-1]
        t = total
        if total > K:
            break
        mi = i
        for j in range(M):
            t += B[j]
            if t > K:
                break
            #print(total)
            mi += 1

        m = max(m, mi)


print(m)

Submission status: Runtime Error

Solution code:
from sys import stdin
from collections import deque as dq
from itertools import zip_longest
n, m, k = map(int, input().split())
a = dq(map(int, stdin.readline().split()))
b = dq(map(int, stdin.readline().split()))

tot = 0
count = 0

i = j = 0
while i < n and j < m:
    # pick one line
    if tot + a[i] + b[j] > k:
        count1 = 0
        ssf = tot
        for ind1 in range(i, n):
            if a[ind1] + ssf > k:
                break
            else:
                ssf += a[ind1]
                count1 += 1

        count2 = 0
        ssf = tot
        for ind2 in range(j, m):
            if b[ind2] + ssf > k:
                break
            else:
                ssf += b[ind2]
                count2 += 1

        if count1 > count2:
            print(count + count1)
        else:
            print(count + count2) 
        exit()

    # pick from any line 
    else:
        if tot + min(a[i], b[j]) > k:
            break
        elif a[i] < b[j]:
            tot += a[i]
            count += 1
            i += 1
        elif b[j] < a[i]:
            tot += b[j]
            count += 1
            j += 1
        else:
            count1 = 0
            for ind1 in range(i, n):
                if a[ind1] <= a[i]:
                    count1 += 1
                else:
                    break
            count2 = 0
            for ind2 in range(j, m):
                if a[ind2] <= b[j]:
                    count2 += 1
                else:
                    break
            
            if count1>count2:
                tot += a[i]
                i += 1
            elif count2<count1:
                tot += b[j]
                j += 1
            else:
                if sum(a[i: min(i + count1 + 1, n)]) < sum(b[j: min(j + count2 + 1, m)]):
                    tot += a[i]
                    i += 1
                else:
                    tot += b[j]
                    j += 1
            count += 1


if i == n and j == m:
    print(count)
elif i < n:
    for ind in range(i, n):
        if tot + a[ind] <= k:
            count += 1
            tot += a[ind]
    print(count)
elif j < m:
    for ind in range(j, m):
        if tot + b[ind] <=k:
            count += 1
            tot += b[ind]
    print(count)




# while tot < k:
#     atop = a[0] if a else 10**10
#     btop = b[0] if b else 10**10

#     # both empty
#     if atop == 10**10 and btop == 10**10:
#         break
    
#     # if adding the minimum crosses k.
#     if tot + min(atop, btop) > k:
#         break
    
#     if tot + atop + b
#     if atop < btop:
#         tot += a.popleft()
#         count += 1
#     elif btop < atop:
#         tot += b.popleft()
#         count += 1
#     else:
#         rema = True
#         for i, j in zip(a, b):
#             if i < j:
#                 rema = True
#                 break
#             elif j < i:
#                 rema = False
#                 break
#             else:
#                 pass
#         if rema:
#             tot += a.popleft()
#             count += 1
#         else:
#             tot += b.popleft()
#             count += 1

Submission status: Runtime Error

Solution code:
k=list(map(int,input().split()))
A=list(map(int,input().split()))
B=list(map(int,input().split()))

a=len(A)
b=len(B)
K=k[2]

t=0
if a<=b:
    if a<=K:
        t=1
    else:
        t=2
elif b<=a:
    if b<=K:
        t=3
    else:
        t=2   

if t==1:
    z=len(A)
elif t==2:
    z=K
else:
    z=len(B)

i=1
for i in range(z):
    if A[i]>B[i]:
        p=B[i]
    elif A[i]<B[i]:
        p=A[i]
    K=K-p
if K<=0:
    print(i+1)

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:
            break
        if len(a) > ai:
            minute += a[ai]
            books += 1
            ai += 1
        elif len(b) > bi:
            minute += b[bi]
            books += 1
            bi += 1

print(books-1)

Submission status: Runtime Error

Solution code:
import numpy as np
import sys
input = sys.stdin.readline
N, M, K=map(int,input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.insert(0, 0)
B.insert(0, 0)
A_sum = [np.sum(A[0:e+1]) for e in range(len(A)) ]
B_sum = [np.sum(B[0:e+1]) for e in range(len(B)) ]
num=0
if len(B)>=len(A):
    for i in range(len(A_sum)):
        for l in range(len(B_sum)):
            if num<i+l:
                Time=A_sum[i]+B_sum[l]
                if Time<=K:
                    num=i+l
else:
   for i in range(len(B_sum)):
        for l in range(len(A_sum)):
            if num<i+l:
                Time=A_sum[i]+B_sum[l]
                if Time<=K:
                    num=i+l 
print(num)

Submission status: Runtime Error

Solution code:
def read(k, a, b, n, m, A, B, r):
    if not (k > 0 and (a < n or b < m)):
        return r
        
    if a == n:
        time = B[b]
    elif b == m:
        time = A[a]
    else:
        time = min(A[a], B[b])

    if k - time < 0:
        return r

    r += 1
    k -= time

    if a == n:
        b += 1
        return read(k, a, b, n, m, A, B, r)
    elif b == m:
        a += 1
        return read(k, a, b, n, m, A, B, r)
    else:
        if A[a] > B[b]:
            b += 1
            return read(k, a, b, n, m, A, B, r)
        elif A[a] < B[b]:
            a += 1
            return read(k, a, b, n, m, A, B, r)
        else:
            return max(read(k, a + 1, b, n, m, A, B, r),
                       read(k, a, b + 1, n, m, A, B, r))


def main():
    n, m, k = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    r = 0
    a = 0
    b = 0
    print(read(k, a, b, n, m, A, B, r))
    # while k > 0 and (a < n or b < m):
    #     if a == n:
    #         time = B[b]
    #     elif b == m:
    #         time = A[a]
    #     else:
    #         time = min(A[a], B[b])

    #     if k - time < 0:
    #         break

    #     r += 1
    #     k -= time
    #     print(k)

    #     if a == n:
    #         b += 1
    #     elif b == m:
    #         a += 1
    #     else:
    #         if A[a] >= B[b]:
    #             b += 1
    #         else:
    #             a += 1

    # print(r)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n, m, k = map((lambda x: int(x)), input().split())
a_list = list(map((lambda x: int(x)), input().split()))
b_list = list(map((lambda x: int(x)), input().split()))
read_cnt = 0
a_cnt = 0
b_cnt = 0
a_list.append(200001)
b_list.append(200001)
val = 'aaaaa'
ans = 'bbbbb'
while k > 0:
    if a_list[a_cnt] > b_list[b_cnt]:        
#         pdb.set_trace()
        k -= b_list[b_cnt]
        b_cnt += 1
        read_cnt += 1
    elif a_list[a_cnt] == b_list[b_cnt]:
        if a_list[a_cnt] == 200001:
            break
        else:
            val, ans = compare_list(a_list, b_list, a_cnt, b_cnt)
            if ans == 'a':
                k -= a_list[a_cnt]
                a_cnt += 1
                read_cnt += 1                
            else:
                k -= b_list[b_cnt]
                b_cnt += 1
                read_cnt += 1
    else:
        k -= a_list[a_cnt]
        a_cnt += 1
        read_cnt += 1
if read_cnt == 1 and k < 0:
    read_cnt -= 1    
print(read_cnt)        
        
def compare_list(a, b, a_cnt, b_cnt):
    dummy_a_cnt = a_cnt
    dummy_b_cnt = b_cnt
    while a_list[dummy_a_cnt] == b_list[dummy_b_cnt]:
        dummy_a_cnt += 1
        dummy_b_cnt += 1
        if a_list[dummy_a_cnt] > b_list[dummy_b_cnt]:
            answer = 'b'
            return b_list[b_cnt], answer
        else:
            answer = 'a'
            return a_list[a_cnt], answer

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
while k>=0:
    if len(a)==0 and len(b)!=0:
        if k>=b[0]:
            ans+=1
            k-=b[0]
            del b[0]
        else:
            break
    elif len(a)!=0 and len(b)==0:
        if k>=a[0]:
            ans+=1
            k-=a[0]
            del a[0]
        else:
            break
    elif len(a)==0 and len(b)==0:
        break
    else:
        mi=min(a[0],b[0])
        if mi>k:
            break
        ans+=1
        k-=mi
        if a[0]>b[0]:
            del b[0]
        elif a[0]<b[0]:
            del a[0]
        else:
            if len(a)==1:
                del b[0]
            elif len(b)==1:
                del a[0]
            else:
                if a[1]>b[1]:
                    del b[0]
                elif a[1]<b[1]:
                    del a[0]
                else:
                  if len(a)==2:
                	del b[0]
            	elif len(a)==2:
                	del a[0]
            	else:
                  if a[2]>=b[2]:
                    del b[0]
                  else:
                    del a[0]
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()))
ans = 0
while (0 < n or 0 < m) and (a[0] <= k or b[0] <= k):
    if (m == 0 and a[0] <= k) or (0 < n and a[0] < b[0] and a[0] <= k):
        k -= a[0]
        del a[0]
        n -= 1
        ans += 1
    elif (n == 0 and b[0] <= k) or (0 < m and b[0] < a[0] and b[0] <= k):
        k -= b[0]
        del b[0]
        m -= 1
        ans += 1
    else:
        break
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()))

count = 0

for x,y in zip(a,b):
  count += min(a[x],b[y])
  if count > k:
    break
    
print(k // 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

#a[n]
#b[m]
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]!=' ':
    b[idid] += (ord(x[i]) - 48) * multi
    multi *= 10
    i+=1
  idid += 1

maxTime = k 
totalNumBooks = n + k
booksRead = 0
#a[]list
#b[]list

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:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
Aa = []
Ba = []
for i in range(N):
    Aa.append(sum(A[:(i+1)]))
for j in range(M):
    Ba.append(sum(B[:(j+1)]))
for l in range(1,400001):
    f = True
    x = 0
    y = 0
    if l >= M:
        x = l-M
    for k in range(x,N+1):
        p = Aa[k]+Ba[l-k]
        if p <= K:
            f = False
            break
    if f:
        print(l-1)
        exit()
print(N+M)

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

ans = 0

def dfs_A(n,m,t,c):
  global ans
  x = t+A_list[n]
  if x > K:
    if c > ans:
      ans = c
  elif x == K:
    if c+1 > ans:
      ans = c+1
  else:
    if n+1 <= N-1 and m <= M-1:
      dfs_A(n+1,m,x,c+1)
    if n <= N and m+1 <= M-1:
      dfs_B(n+1,m,x,c+1)

def dfs_B(n,m,t,c):
  global ans
  x = t+B_list[m]
  if x > K:
    if c > ans:
      ans =c
  elif x == K:
    if c+1 > ans:
      ans = c+1
  else:
    if n+1 <= N-1 and m <= M-1:
      dfs_A(n,m+1,x,c+1)
    if n <= N and m+1 <= M-1:
      dfs_B(n,m+1,x,c+1)

dfs_A(0,0,0,0)
dfs_B(0,0,0,0)
print(ans)