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:
#!/usr/bin/env python3

import sys
import pprint

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)

def upper_case(lst, key):
	ng = -1
	ok = len(lst)
	while (abs(ok - ng) > 1):
		mid = (ok + ng) // 2
		if lst[mid] > key:
			ok = mid
		else:
			ng = mid
	return ok




def main():
	log = Logger(0)
	n, m, k = map(int, sys.stdin.readline().split())
	a = list(map(int, sys.stdin.readline().split()))
	b = list(map(int, sys.stdin.readline().split()))
	for i in range(1, n):
		a[i] += a[i-1]
	for i in range(1, m):
		b[i] += a[i-1]
	log.print(a, b)
	ans = 0
	for i in range(-1, n):
		if i == -1:
			ans = max(ans, upper_case(b, k))
			continue
		if a[i] > k:
			continue
		ans = max(ans, i+1+upper_case(b, k-a[i]))
		log.print(i, k-a[i], upper_case(b, k-a[i]))
	print(ans)


main()

Submission status: Runtime Error

Solution code:
import sys
from typing import Callable, List, NoReturn, Set, Tuple


def main() -> NoReturn:
    readline: Callable[[], str] = sys.stdin.readline

    n, m, k = map(int, readline().rstrip().split())  # type: int, int, int
    a: List[int] = []
    for a_i in readline().rstrip().split():
        a.append(a_i)
    b: List[int] = []
    for b_i in readline().rstrip().split():
        b.append(b_i)

    stack: List[Tuple] = [(0, 0, 0)]
    searched: Set[Tuple] = set()
    results: List[Tuple] = []

    while stack:
        current = stack.pop()
        result_flag = True
        if current not in searched:
            next_a, next_b, total_time = current
            read_a = total_time + a[next_a]
            read_b = total_time + b[next_b]
            if read_b <= k:
                stack.append((next_a, next_b + 1, read_b))
                result_flag = False
            if read_a <= k:
                stack.append((next_a + 1, next_b, read_a))
                result_flag = False
            if result_flag:
                results.append(current)
            searched.add(current)
            
    print(max(map(lambda t: t[0] + t[1], results)))
            

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
"""everything has a cost!"""

from math import *
import random
import functools
import collections
import sys

__author__ = 'p7x'


# sys.stdin = open('in.txt', 'r')
# sys.stdout = open('out.txt', 'w')
# sys.stderr = open('err.txt', 'w')

i, j = 0, 0
n, m = 0, 0


@functools.lru_cache(maxsize=None, typed=False)
def read(ti: int, tj: int) -> int:
    if (ti < n and (tj == m or a[ti] < b[tj])):
        return 1
    elif (tj < m and (ti == n or b[tj] < a[ti])):
        return 2
    elif (ti < n and tj < m and a[ti] == b[tj]):
        return read(ti+1, tj+1)
    else:
        if (ti == i):
            return 3
        else:
            return 1


if __name__ == '__main__':
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    mins = 0
    while (mins < k):
        v = read(i, j)
        if (v == 1):
            mins += a[i]
            i += 1
        elif (v == 2):
            mins += b[j]
            j += 1
        else:
            break
    if mins > k:
        print(i+j-1)
    else:
        print(i+j)

Submission status: Runtime Error

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=0
count=0
while c+min(a[0],b[0])<=k:
  
 c+=min(a[0],b[0])
 count+=1
 if min(a[0],b[0])==a[0]:
   a.remove(a[0])
 else:
   b.remove(b[0])         
print(count)

Submission status: Runtime Error

Solution code:
n, m, k = input().split(' ')
a = input().split(' ')
b = input().split(' ')

n = int(n)
m = int(m)
k = int(k)

a = list(map(int, a))
b = list(map(int, b))
times = 0
book = 0

while(True):

  if len(a) == 0 or a[0] >= b[0]:
    if (times + b[0]) > k:
      break
    times += b[0]
    b.pop(0)
    book += 1
  elif len(b) == 0 or a[0] < b[0]:
    if (times + a[0]) > k:
      break
    times += a[0]
    a.pop(0)
    book += 1

  if len(a) == 0 and len(b) == 0:
    break

print(book)

Submission status: Runtime Error

Solution code:
import sys
n,m,k= map(int,input().split())
la = list(map(int,input().split()))
lb = list(map(int,input().split()))
c=0
if k<la[0] and k<lb[0]:
  print(0)
  sys.exit()
while len(lb)>0 and len(la)>0:
    a=la[0]
    b=lb[0]
    if a<b:
        k=k-a
        la.remove(la[0])
        c+=1
        if k<0:
            print(c-1)
            sys.exit()
    if a>b:
        k=k-b
        lb.remove(lb[0])
        c+=1
        if k<0:
            print(c-1)
            sys.exit()
    if a==b:
        a=la[1]
        b=lb[1]
        if a<b:
            k=k-la[0]
            la.remove(la[0])
            c+=1
            if k<0:
                print(c-1)
                sys.exit()
        if a>b:
            k=k-lb[0]
            c+=1
            lb.remove(lb[0])
            if k<0:
                print(c-1)
                sys.exit()
if len(la)==0 and len(lb)!=0:
  for i in range(len(lb)):
    k=k-lb[0]
    lb.remove(lb[0])
    c+=1
    if k<0:
        print(c-1)
        sys.exit()
if len(lb)==0 and len(la)!=0:
  for i in range(len(la)):
    k=k-la[0]
    la.remove(la[0])
    c+=1
    if k<0:
        print(c-1)
        sys.exit()

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
while K >= A[a] or K >= B[b] :
    if A[a]>B[b]:
        K -= B[b]
        b+=1
    else:
        K -= A[a]
        a+=1
    #print(a,b)
        
print(a+b)

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

ia = 0
ib = 0
book = 0
minute = 0

while minute < k:
    if a[ia] > b[ib]:
        minute += b[ib]
        book += 1
        if minute > k:
            book -= 1
        ib += 1
        if ib > m:
            ib = m
    else:
        minute += a[ia]
        book += 1
        if minute > k:
            book -= 1
        ia += 1
        if ia > n:
            ia = n
    

print(book)

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

ans = 0
def dfs(a, b, k):
	global ans

	if a == N and b ==M:
		return True

	if a < N and k >= A[a] and dfs(a + 1, b, k - A[a]):
		ans += 1
		return True

	if b < M and k >= B[b] and dfs(a, b + 1, k - B[b]):
		ans += 1
		return True

	if k <= 0:
		return False

	return True

dfs(0, 0, K)
print(ans)

Submission status: Runtime Error

Solution code:
import functools
import sys

sys.setrecursionlimit(10 ** 5)

def solve(A, B, K):

    NA = len(A)
    NB = len(B)

    @functools.lru_cache(None)
    def rec(a, b, sum_so_far):

        if sum_so_far >= K:
            return 0

        ans = 0
        if a < NA and A[a] + sum_so_far <= K:
            ans = max(ans, 1 + rec(a + 1, b, A[a] + sum_so_far))

        if b < NB and B[b] + sum_so_far <= K:
            ans = max(ans, 1 + rec(a, b + 1, B[b] + sum_so_far))

        return ans

    return rec(0, 0, 0)

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

print(solve(A, B, K))

Submission status: Runtime Error

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

for i in range(n):
    if a[i]>k:
        read=i
        break
if a[n-1]<k:
    read=n
time=a[read-1]
ans=read
start=read-1
if read==n:
    for i in range(m):
        if time+b[i]>k:
            read+=i
            ans=max(ans,read)
            read-=i
        if i==m-1:
            print(n+m)
            exit()
            
for i in range(start+1):
    read-=1
    time-=a[start-i]
    for j in range(m):
        if time+b[j]>k:
            read+=j
            ans=max(ans,read)
            read-=j
            break
        if j==m-1:
            read+=m
            print(max(ans,read))
            exit()
print(ans)

Submission status: Runtime Error

Solution code:
from collections import defaultdict

def dp(x,y,k):
  if cache[(x,y)] != -1:
    return cache[(x,y)]
  global n,m,a,b
  p1 = 0
  p2 = 0
  if x < n and a[x] <= k:
    if cache[(x+1,y)] == -1:
      cache[(x+1,y)] = 1+dp(x+1,y,k-a[x])
    p1 = cache[(x+1,y)]
  if y < m and b[y] <= k:
    if cache[(x,y+1)] == -1:
      cache[(x,y+1)] = 1+dp(x,y+1,k-b[y])
    p2 = cache[(x,y+1)]
  cache[(x,y)] = max(p1,p2)
  return cache[(x,y)]

cache = defaultdict(lambda:-1)
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
print(dp(0,0,k))

Submission status: Runtime Error

Solution code:
N,M,K = map(int, input().split())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
r = K
c = 0
while True:
  ar = 0
  br = 0
  if r <= 0:
    break
  if len(As) == 0 and len(Bs) == 0:
    break
  if (len(As) < 0 and (r - As[0]) < 0) and (len(Bs) < 0 and (r - Bs[0]) < 0):
    break

  if 0 < len(As):
    ar = As[0]
  if 0 < len(Bs):
    br = Bs[0]

  if 0 < ar and ar <= br:
    r = r - As[0]
    if 1 <= len(As):
      del As[0]
    if 0 <= r:
      c += 1
  else:
    r = r - Bs[0]
    if 1 <= len(Bs):
      del Bs[0]
    if 0 <= r:
      c += 1
print(c)

Submission status: Runtime Error

Solution code:
a=input()
l=a.split()
n=int(l[0])
m=int(l[1])
k=int(l[2])
a=input()
aa=a.split()
b=input()
bb=b.split()
time=0
bookcount=0

while time<k:
  if int(aa[0])<int(bb[0]):
    bookcount=bookcount+1
    time=time+int(aa[0])
    aa=aa[1:]

  else:
    bookcount=bookcount+1
    time=time+int(bb[0])
    bb=bb[1:]    


print(bookcount-1)

Submission status: Runtime Error

Solution code:
N = int(input())

M= int(input())


K=int(input())

arr = input()   # takes the whole line of n numbers
A= list(map(int,arr.split(' '))) 

i=0

arra = input()   # takes the whole line of n numbers
B= list(map(int,arra.split(' '))) 


if(A[0]<K):
    K=K-A[0]
    i=i+1
if(B[0]<K):
    K=K-B[0]
    i=i+1

print(i)

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
def dfs(i, j, cost):
    global ans
    if cost > K:
        ans = max(ans, i+j-1)
        return
    if i == N and j==M:
        ans = j+i
        return
    if i==N and j<M:
        dfs(i, j+1, cost+B[j])
        return
    if j==M and i<N:
        dfs(i+1, j, cost+A[i])
        return
    else:
        dfs(i+1, j, cost+A[i])
        dfs(i, j+1, cost+B[j])
    return
dfs(0, 0, 0)
print(ans)

Submission status: Runtime Error

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

data2cnt=0
data3cnt=0
total=0
count=0
maxint=n+m

for i in range(maxint):
  if len(data2)>=data2cnt+1 and int(data2[data2cnt]) < int(data3[data3cnt]):
      if k>=total+data2[data2cnt]:
        total=total+int(data2[data2cnt])
        data2cnt=data2cnt+1
  elif len(data3)>=data3cnt+1:
      if k>=total+data3[data3cnt]:
        total=total+int(data3[data3cnt])
        data3cnt=data3cnt+1
  else:
    break

print(str(data2cnt+data3cnt))

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 = list(reversed(A))
BB = list(reversed(B))

rest = K
ans = 0

def dfs(cost, aindex, bindex, score):

    if K == cost:
        # print("1:", score, cost)
        return score
    elif K < cost:
        # print("2:", score, cost)
        return score - 1
        # return -1
    
    if aindex == N and bindex == M:
        # print("3:", score, cost)
        return score

    if aindex >= N:
        return dfs(cost + B[bindex], aindex, bindex+1, score + 1)
    
    elif bindex >= M:
        return dfs(cost + A[aindex], aindex+1, bindex, score + 1)

    else:
        return max(dfs(cost + A[aindex], aindex+1, bindex, score + 1), dfs(cost + B[bindex], aindex, bindex + 1, score + 1))

print(max(dfs(A[0], 1, 0, 1), dfs(B[0], 0, 1, 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

for i in range(N):
    for j in range(M):
        if A[i] <= B[j] and K >= A[i]:
            K = K - A[i]
            i += 1
            count += 1
        elif B[j] <= A[i] and K >= B[j]:
            K = K - B[j]
            j += 1
            count += 1
        
        if i == N-1:
            for k in range(j,M):
                if B[k] <= K:
                    K = K - B[k]
                    count += 1
                    
        if j == M-1:
            for l in range(i,N):
                if A[l] <= K:
                    K = K - A[l]
                    count += 1
                    
print(count)

Submission status: Runtime Error

Solution code:
def mi(): return map(int,input().split())
def lmi(): return list(map(int,input().split()))
def ii(): return int(input())
def isp(): return input().split()

from collections import deque
n,m,k=mi()
a=deque(lmi())
b=deque(lmi())
i=0
cnt=0
value=0
while a or b:
  try:
    r=a[i]
  except:
    r=float('inf')
  try:
    q=b[i]
  except:
    q=float('inf')
  if q==r:
    if a[1]<b[1]:
      p=a.popleft()
    elif a[1]>b[1]:
      p=b.popleft()
  else:
    p=min(q,r)
    if p==r:
      p=a.popleft()
    else:
      p=b.popleft()
    
  print(p)
  
  value+=p
  if value>k:
    break
  elif value==k:
    cnt+=1
    break
  cnt+=1
  
  
  
print(cnt)

Submission status: Runtime Error

Solution code:
N, M, K = map(int, input().split())
A = [0]*200000
B = [0]*200000
A_ele=list(map(int, input().split()))
B_ele=list(map(int, input().split()))
for i in range(len(A_ele)):
    A[i] = A_ele[i]
for i in range(len(B_ele)):
    B[i] = B_ele[i]
sum = cnt = 0
i = j = 0
while True:
    if A[i] != 0 and B[j] != 0:
        if A[i] < B[j]:
            sum += A[i]
            i += 1
        else:
            sum += B[j]
            j += 1
    else:
        sum += A[i] + B[j]
        if A[i] == 0:
            j += 1
        else:
            i += 1

    if sum > K:
        break
    if A[i] == B[j] == 0:
        cnt+=1
        break
    cnt += 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()))

ca = 0
cb = 0
count = 0
ea = False
eb = False
while k > 0:
  if ea and eb:
    break
  elif ea:
    if b[cb] <= k:
        k = k - b[cb]
        count += 1
        cb += 1
        if(cb == m):
          eb = True
    else:
      break
  elif eb:
    if a[ca] <= k:
        k = k - a[ca]
        count += 1
        ca += 1
        if(ca == n):
          ea = True
    else:
      break
  else:
    if a[ca] <= b[cb]:
      if a[ca] <= k:
        k = k - a[ca]
        count += 1
        ca += 1
        if(ca == n:
          ea = True
      else:
        break
    else:
      if b[cb] <= k:
        k = k - b[cb]
        count += 1
        cb += 1
        if(cb == m):
          eb = True
      else:
        break

print(count)

Submission status: Runtime Error

Solution code:
import numpy as np

N, M, K = map(int, input().split())
A = [int(n) for n in input().split()]
B = [int(n) for n in input().split()]

A = np.array(A)
B = np.array(B)

A = np.cumsum(A)
B = np.cumsum(B)

A1 = np.zeros((len(A),2))
A1[:,0] = A
A1[:,1] = np.arange(1,len(A)+1)

B1 = np.zeros((len(B),2))
B1[:,0] = B
B1[:,1] = np.arange(1,len(B)+1)

C1 = np.zeros((len(A)*len(B),2))
lenB = len(B)
for i in range(len(A)):
    for j in range(len(B)):
        C1[lenB*i+j,:] = A1[i,:] + B1[j,:]
C2 = np.array([[Cl[0],Cl[1]] for Cl in C1 if Cl[0] <= K])

if len(C2):
  print(int(C2[:,1].max()))
else:
  print(0)

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

    def dfs(n, i, j, d, k):
        if k >= K or (i == N and j == M):
            return n
        if d == 1 and i < N and k + A[i] <= K:
            k += A[i]
            l = dfs(n + 1, i + 1, j, d, k)
            if j < M:
                r = dfs(n + 1, i + 1, j, -d, k)
        elif d == -1 and j < M and k + B[j] <= K:
            k += B[j]
            l = dfs(n + 1, i, j + 1, d, k)
            if i < N:
                r = dfs(n + 1, i, j + 1, -d, k)
        else:
            return n

        return max(l, r)

    print(dfs(0, 0, 0, 1, 0))

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()))
ans=0
i=0
j=0
while k>=0:
    if i==n and j<m:
        k=k-b[j]
        j+=1
        ans+=1
    elif j==m and i<n:
        k=k-b[i]
        i+=1
        ans+=1
    elif i<n and j<m:
        if a[i]<b[j]:
            k=k-a[i]
            i+=1
            ans+=1
        else:
            k=k-b[j]
            j+=1
            ans+=1
    else:break
if k<0:
    print(ans-1)
else:
    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
seted=[]

for i in range(n+m):
  if not a:
    seted.append(b[0])
    del b[0]
    continue
    
  else:
    if a[0]<=b[0]:
      seted.append(a[0])
      del a[0]
      continue
    
  if not b:
    seted.append(a[0])
    del a[0]
    continue
  
  else:
    if a[0]>=b[0]:
      seted.append(b[0])
      del b[0]
      continue

for i in seted:
  if k-i>=0:
    count+=1
    k-=i
    
  else:
    break
      
print(count)

Submission status: Runtime Error

Solution code:

import functools

def solve(A, B, K):

    NA = len(A)
    NB = len(B)

    @functools.lru_cache(None)
    def rec(a, b, sum_so_far):

        if sum_so_far >= K:
            return 0

        ans = 0
        if a < NA and A[a] + sum_so_far <= K:
            ans = max(ans, 1 + rec(a + 1, b, A[a] + sum_so_far))

        if b < NB and B[b] + sum_so_far <= K:
            ans = max(ans, 1 + rec(a, b + 1, B[b] + sum_so_far))

        return ans

    return rec(0, 0, 0)

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

print(solve(A, B, K))

Submission status: Runtime Error

Solution code:
a=input()
l=a.split()
n=int(l[0])
m=int(l[1])
k=int(l[2])
a=input()
aa=a.split()
b=input()
bb=b.split()
time=0
bookcount=0

while time<k:
  if int(aa[0])<int(bb[0]):
    bookcount=bookcount+1
    time=time+int(aa[0])
    aa=aa[1:]
    #print(aa)
    print(time)
  else:
    bookcount=bookcount+1
    time=time+int(bb[0])
    bb=bb[1:]    
    #print(bb)
    print(time)


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

Submission status: Runtime Error

Solution code:
from itertools import accumulate
enum = enumerate

R = lambda: map(int, input().split())
*_, k = R()
a = accumulate(R())
b = tuple(accumulate(R()))
print(max(i + j for i, x in enum(a, 1) for j, y in enum(b, 1) if x + y <= k))

Submission status: Runtime Error

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

a_li = [0] + a_li
b_li = [0] + b_li

time = 0
ans = 0
a = 0
temp = 0

a_wa = [0] * (n+10)
b_wa = [0] * (m+10)

s = 0
for i in range(n+1):
    s += a_li[i]
    a_wa[i] = s

s = 0
for i in range(m+1):
    s += b_li[i]
    b_wa[i] = s
    

for i in range(n+1):
    for j in range(min(temp-i, m), m+1):
        time = a_wa[i] + b_wa[j]
        if time <= k:
            ans = max(ans, i+j)
            temp = ans
        else:
            break
            
print(ans)

Submission status: Runtime Error

Solution code:
inp = input().split(" ")
time = int(inp[2]);
ls1 = input().split(" ")
ls1 = [int(i) for i in ls1]
ls2 = input().split(" ")
ls2 = [int(i) for i in ls2]
ls1 = ls1 + ls2
sort(ls1)
n=0
total =0
for i in ls1:
 if total+i <= time:
  total+=i
  n+=1
 else:
  break
print(n)

Submission status: Runtime Error

Solution code:
#include<stdio.h>

int main(void){
    int N,M,K,n=0,time=0;
    scanf("%d %d %d", &N, &M, &K);

    int A[N],B[M];
    for(int i=0;i<N;i++){
        scanf("%d", &A[i]);
    }
    for(int j=0;j<M;j++){
        scanf("%d", &B[j]);
    }

    int a=0;
    int b=0;
    for(;;){
        if(A[a]-B[b]>0){
            time += B[b];
            b++;
            n++;
            if(time > K){
                time -= B[b];
                break;
            }
        }
        else{
            time += A[a];
            a++;
            n++;
            if(time > K){
                time -= A[a];
                break;
            }
        }

    }

    printf("%d", n);
}

Submission status: Runtime Error

Solution code:
def see_next(N, M, As, Bs, a, b):
  if a == N and b == M:
    return 1
  elif As[a] < Bs[b]:
    return 1
  elif As[a] > Bs[b]:
    return 0
  elif As[a] == Bs[b]:
    return see_next(N, M, As, Bs, a+1, b+1)

N, M, K = map(int,input().split())
As = list(map(int,input().split()))
Bs = list(map(int,input().split()))
As.append(K+1)
Bs.append(K+1)
a = 0
b = 0
time = 0
ans = -1
while time <= K:
  ans += 1
  if a == N and b == M:
    break
  elif As[a] < Bs[b]:
    time += As[a]
    # print(As[a])
    a += 1
  elif As[a] > Bs[b]:
    time += Bs[b]
    # print(Bs[b])
    b += 1
  elif As[a] == Bs[b]:
    if see_next(N, M, As, Bs, a+1, b+1):
      time += As[a]
      a += 1
    else:
      time += Bs[b]
      b += 1
  
print(ans)

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

ans = 0
def dfs(a, b, k):
	global ans

	if a == N and b ==M:
		return True

	if k >= A[a] and dfs(a + 1, b, k - A[a]):
		ans += 1
		return True

	if k >= B[b] and dfs(a, b + 1, k - B[b]):
		ans += 1
		return True

	if k <= 0:
		return False

	return True

dfs(0, 0, K)
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)
i=0
j=0
cnt=0
time=0
if sum(A)+sum(B)<=K:
    cnt = len(A)+len(B)
elif A[0]>K and B[0]>K:
    cnt = 0
else:
    for n in range(200000):
        if A[i]<B[j]:
            
            time = time+A[i]
            i = i+1
            if time>K:
                break
            else:
                cnt=cnt+1
        elif A[i]>B[j]:
            time = time+B[j]
            j = j+1
            if time>K:
                break
            else:
                cnt=cnt+1
        else:
            
            if A[i+1]>B[j+1]:
                time = time+B[j]
                j = j+1
                if time >K:
                    break
                else:
                    cnt = cnt+1
            else:
                time = time+A[i]
                i = i+1
                if time > K :
                    break
                else:
                    cnt = cnt+1
            
print(cnt)

Submission status: Runtime Error

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

if __name__ == '__main__':
  n,m,k=map(int,input().strip("\n").split())
  A=list(map(int,input().strip("\n").split()))
  B=list(map(int,input().strip("\n").split()))
#  A.append(10**9+1)
#  B.append(10**9+1)

  def dfs(a,b,k,s):
    if k<0:
      return s-1
    if k==0:
      return s
    if a<n:
      ansA=dfs(a+1,b,k-A[a],s+1)
    else:
      ansA=s
    if b<m:
      ansB=dfs(a,b+1,k-B[b],s+1)
    else:
      ansB=s
    return max(ansA,ansB)

  ans=dfs(0,0,k,0)
  print(ans)

Submission status: Runtime Error

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

for i in range(n):
    if a[i]>k:
        read=i
        break
if a[n-1]<k:
    read=n
time=a[read-1]
ans=read
start=read-1
if read==n:
    for i in range(m):
        if time+b[i]>k:
            read+=i
            ans=max(ans,read)
            read=-i
        if i==m-1:
            print(n+m)
            exit()
            
for i in range(start+1):
    read-=1
    time-=a[start-i]
    for j in range(m):
        if time+b[j]>k:
            read+=j
            ans=max(ans,read)
            read-=j
            break
        if j==m-1:
            read+=m
            print(max(ans,read))
            exit()
print(ans)

Submission status: Runtime Error

Solution code:

NIF = float('-INF')
def calculate(A,B, K, ai, bi, book_count, times):
	m = NIF
	if times > K:
		return book_count-1
	if times == K or (ai >= len(A) and bi >= len(B)):
		return book_count
	
	# select A
	if ai < len(A):
		c = calculate(A,B, K, ai+1, bi, book_count+1, times + A[ai])

		if c > m:
			m = c
		

	# select B
	if bi < len(B):
		c = calculate(A,B, K, ai, bi+1, book_count+1, times + B[bi])

		# backtrack
		if c > m:
			m = c
	return m

N, M, K = map(int, input().split())
A, B = [], []
if N > 0:
	A = list(map(int, input().split()))
if M > 0:
	B = list(map(int, input().split()))

print(calculate(A,B, K, 0, 0, 0, 0))

Submission status: Runtime Error

Solution code:
import numpy as np
n,m,k=map(int,input().split())

A=np.int64([int(i) for i in input().split()])

B=np.int64([int(i) for i in input().split()])

count=0
time=0
for i in range(1,n+m+1):
    if ((time>k)|((A[0]==0)&(B[0]==0))):
        break
    if A[0]>B[0]:
        count+=1
        time+=A[0]
        A=A[1:]
    elif A[0]<B[0]:
        count+=1
        time+=B[0]
        B=B[1:]
    if A==[]:
        A.append(0)
    if B==[]:
        B.append(0)
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())) 

sum_time = 0
count = 0

while sum_time<K:
    if not A[0] and not B[0]:
        break
    if A[0] <= B[0] or not B[0]:
        sum_time+=A[0]
        A.pop(0)
    elif A[0] >= B[0] or not A[0]:
        sum_time+=B[0]
        B.pop(0)
    count+=1
if sum_time>K:
    count-=1
print(count)

Submission status: Runtime Error

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

a = [int(w) for w in input().split()]
b = [int(w) for w in input().split()]

ans = 0

if k < a[0] or k < b[0]:
    print(0)
    
else:
    t = 0
    i = 0
    j = 0
    z = min(n, m)
    while(k > 0 and (i < n or j < m)):
        if i < n and (a[i] < b[j]):
                k -= a[i]
                i += 1
        
        elif j < m:
            k -= b[j]
            j += 1
            #print("**")
            #print(t, ans)
            
        if k>=0:
            ans+=1
    print(ans)

Submission status: Runtime Error

Solution code:
A = []
B = []
N = int(input())
M = int(input())
K = int(input())

for i in range(N):
  A.append(int(input()))
for j in range(M):
  B.append(int(input()))
           
red_book = 0
red_time = 0
books = A + B
books = sorted(books)
for book in books:
    red_time += book
    if red_time < K:
        red_book += 1
    else:
        break
    
print(red_book)

Submission status: Runtime Error

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

while min(len(A),len(B)) > 0 and minute < K:
    if A[0] >= B[0]:
        minute += A[0]
        A.pop(0)
    else:
        minute += B[0]
        B.pop(0)
    count += 1


if minute > K:
    print(count - 1)
    exit()
if len(A) == 0:
    while len(B) > 0 and minte < K:
        minute += B[0]
        B.pop(0)
        count += 1
else:
    while len(A) > 0 and minute < K:
        minute += A[0]
        A.pop(0)
        count += 1

if minute > K:
    print(count -1)
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()))
i,j=0,0
N-=1
M-=1
tim=0
book=0
a,b=True,True
while a or b:
	if i<=N and a:
		tim+=A[i]
		i+=1
		if tim>K:
			tim-=A[i]
			a=False
		else:
			book+=1
	else:
		a=False
	
	if j<=M and b:
		tim+=B[j]
		j+=1
		if tim>K:
			tim-=B[j]
			b=False
		else:
			book+=1
	else:
		b=False
print(book)

Submission status: Runtime Error

Solution code:
#include<stdio.h>

int main(void){
    int N,M,K,n=0,time=0;
    scanf("%d %d %d", &N, &M, &K);

    int A[N],B[M];
    for(int i=0;i<N;i++){
        scanf("%d", &A[i]);
    }
    for(int j=0;j<M;j++){
        scanf("%d", B[j]);
    }

    int a=0;
    int b=0;
    for(;;){
        if(A[a]-B[b]>0){
            time += B[b];
            b++;
            n++;
            if(time > K){
                time -= B[b];
                break;
            }
        }
        else{
            time += A[a];
            a++;
            n++;
            if(time > K){
                time -= A[a];
                break;
            }
        }

    }

    printf("%d", n);
}