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 resolve():
    import sys
    input = sys.stdin.readline
    # 整数 1 つ
    # n = int(input())
    # 整数複数個
    n, m, k = map(int, input().split())
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

    cnt_A = 0
    cnt_B = 0
    readtime = 0
    time_max = 10**9 + 1

    for i in range(n+m):
        readtime += min(A[cnt_A], B[cnt_B])
        if readtime > k:
            readtime -= min(A[cnt_A], B[cnt_B])
            break
        else:
            if A[cnt_A] <= B[cnt_B]:
                cnt_A += 1
                if cnt_A == n:
                    A.append(time_max)
            else:
                cnt_B += 1
                if cnt_A == n:
                    A.append(time_max)

        #
        # if len(A) > 0 and len(B) > 0:
        #     readtime += min(A[0], B[0])
        #     if readtime > k:
        #         readtime -= min(A[0], B[0])
        #         break
        #     else:
        #         if A[0] <= B[0]:
        #             cnt_A += 1
        #             del A[0]
        #         else:
        #             cnt_B += 1
        #             del B[0]
        #
        # elif len(A) == 0:
        #     readtime += B[0]
        #     if readtime > k:
        #         readtime -= B[0]
        #         break
        #     else:
        #         cnt_B += 1
        #         del B[0]
        #
        # else:
        #     readtime += A[0]
        #     if readtime > k:
        #         readtime -= A[0]
        #         break
        #     else:
        #         cnt_A += 1
        #         del A[0]

    print(cnt_A + cnt_B)


resolve()

Submission status: Runtime Error

Solution code:
def main():
    n, m, k, *ab = map(int, open(0).read().split())
    a = ab[:n] + [float("Inf")] * m
    b = ab[n:] + [float("Inf")] * n

    i = 0
    j = 0
    total = 0
    for _ in range(n + m + 1):
        x = a[i]
        y = b[j]

        if x == y:
            if total + x > k:
                break
            else:
                total += x
                if x[i + 1] <= y[j + 1]:
                    i += 1
                else:
                    j += 1
        elif x < y and total + x <= k:
            total += x
            i += 1
        elif x > y and total + y <= k:
            total += y
            j += 1
        else:
            break

    print(i + j)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from sys import stdin
import sys
import math
import random
from decimal import Decimal


N, M, K = [int(x) for x in stdin.readline().rstrip().split()]
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.append(10**10)
B.append(10**10)
c1 = 0
c2 = 0
flag = 0
while True:
    if K < A[c1] and K < B[c2]:
        break
    if A[c1] < B[c2]:
        K = K-A[c1]
        c1 += 1
    elif A[c1] > B[c2]:
        K = K-B[c2]
        c2 += 1
    else:
        t1 = c1+1
        t2 = c2+1
        while True:
            if A[t1] < B[t2]:
                K = K-A[c1]
                c1 += 1
                break
            elif A[t1] > B[t2]:
                K = K-B[c2]
                c2 += 1
                break
            else:
                t1 = t1+1
                t2 = t2+1
print(c1+c2)

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()))
ct=0
ans=0
while 1:
    if a[0]<b[0]:
        if ct+a[0]>k:
            break
        ct+=a[0]
        a.pop(0)
        a.append(99999999)
    elif a[0]>b[0]:
        if ct+b[0]>k:
            break
        ct+=b[0]
        b.pop(0)
        b.append(999999999)
    else:
        if ct+b[0]>k:
            break
        ct+=a[0]
        if a[1]>b[1]:
            a.pop(0)
            a.append(99999999)
        elif a[1]<b[1]:
            b.pop(0)
            b.append(999999999)
    ans+=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()))
t = 0
cnt = 0
for i in range(n + m):
    if a[0] <= b[0]:
        t += a[0]
        del a[0]
    else:
        t += b[0]
        del b[0]
    if t >= k:
        break
    else:
        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()))
time = 0
cnt = 0
ia = 0
ib = 0
while True:
    if cnt == n + m:
        break
    elif ia > len(a) - 1 or a[ia] > b[ib]:
        time += b[ib]
        if time > k:
            break
        ib += 1
        cnt += 1
    else:
        time += a[ia]
        if time > k:
            break
        ia += 1
        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()))
total = 0
count = 0
for i in range(n + m):
    if A[0] == min(A[0], B[0]):
        total += A.pop(0)
    elif B[0] == min(A[0], B[0]):
        total += B.pop(0)
    if total > k:
        break
    count += 1
print(count)

Submission status: Runtime Error

Solution code:
import sys

N,M,K = map(int, sys.stdin.readline().strip().split())
A = list(map(int, sys.stdin.readline().strip().split()))
B = list(map(int, sys.stdin.readline().strip().split()))

count = 0
k = K

if K < A[0] and K < B[0]:
    print(0)
    sys.exit()

if sum(A) + sum(B) <= K:
    print(N + M)
    sys.exit()

while k >= 0:
    if A[0] > B[0]:
        k -= B.pop(0)
        count += 1
    elif A[0] < B[0]:
        k -= A.pop(0)
        count += 1
    else:
        k -= A.pop(0)
        count += 1

print(count - 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:
    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:
import sys
sys.setrecursionlimit(400010)

from sys import stdin
input = stdin.readline
def Tsundoku(i,j,k,n,m,dp,a,b):
    if (i,j) in dp:
        return dp[(i,j)]
    ans1,ans2 = 0,0
    if i<n and k-a[i]>=0:
        ans1 = 1+Tsundoku(i+1,j,k-a[i],n,m,dp,a,b)
    if j<m and k-b[j]>=0:
        ans2 = 1+Tsundoku(i,j+1,k-b[i],n,m,dp,a,b)
    dp[(i,j)] = max(ans1,ans2)
    return dp[(i,j)]
        
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
dp = dict()
ans = Tsundoku(0,0,k,n,m,dp,a,b)
print(ans)

Submission status: Runtime Error

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

cnt=0
ans=0

for i in range(10**9):
    if A==[] and B==[]:
        print(ans)
        exit()

    elif A==[] and B!=[]:
        cnt+=B[0]
        B.remove(B[0])
        ans+=1
    elif B==[] and A!=[]:
        cnt+=A[0]
        A.remove(A[0])
        ans+=1
    else:
        cnt+=min(A[0],B[0])

        if cnt>K:
            print(ans)
            exit()
        else:
            ans+=1

        if A[0]==min(A[0],B[0]) and B[0]!=min(A[0],B[0]):
            A.remove(A[0])
        elif B[0]==min(A[0],B[0]) and A[0]!=min(A[0],B[0]):
            B.remove(B[0])
        else:
            for i in range(1,10**9):
                if B[i]==A[i]:
                    pass
                else:
                    if A[i]<B[i]:
                        A.remove(A[0])
                        break
                    else:
                        B.remove(B[0])
                        break

Submission status: Runtime Error

Solution code:
import numpy as np

N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
cost = 0
ind_a = 0
ind_b = 0
max_book = 0
dp = np.zeros((N + 1, M + 1)).astype(int)
while True:
    if ind_a < N and ind_b <= M:
        dp[ind_a + 1, ind_b] = dp[ind_a, ind_b] + A[ind_a]
        ind_a += 1
        if dp[ind_a, ind_b] <= K and ind_a + ind_b > max_book:
            max_book = ind_a + ind_b
    if ind_b < M and ind_a <= N:
        dp[ind_a, ind_b + 1] = dp[ind_a, ind_b] + B[ind_b]
        ind_b += 1
        if dp[ind_a, ind_b] <= K and ind_a + ind_b > max_book:
            max_book = ind_a + ind_b

    if ind_a == N and ind_b == M:
        break
print(max_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()))

a = 0
b = 0
La = len(A)
Lb = len(B)
ans = 0
S = 0
while S <= K:
  if a == N and n == M:
    ans += 1
    break
  if a == N:
    va = 10000000000000
  else:
    va = A[a]
  if b == M:
    vb = 10000000000000
  else:
    vb = B[b]
    
  if a  < b:
    a += 1
    S  += va
    ans += 1
  else:
    b += 1
    S += vb
    ans += 1
 
  
print(ans-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()))
minutes = 0

if sum(a) + sum(b) <= k:
  ans = len(a) + len(b)
  print(ans)
else:
  while minutes <= k:
    if a[0] <= b[0]:
      minutes += a[0]
      a.pop(0)
    else:
      minutes += b[0]
      b.pop(0)
  ans = n + m - len(a) - len(b) - 1
  print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
import pandas as pd


N, M, K = map(int, input().split())
A = [n for n in input().split()]
B = [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,:]
C1 = pd.DataFrame(C1)
C1 = C1[C1[0] <= K]

print(int(C1[1].max())

Submission status: Runtime Error

Solution code:
def resolve():
    import sys
    input = sys.stdin.readline
    # 整数 1 つ
    # n = int(input())
    # 整数複数個
    n, m, k = map(int, input().split())
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

    cnt_A = 0
    cnt_B = 0
    readtime = 0
    time_max = 10**9 + 1

    for i in range(n+m):
        readtime += min(A[cnt_A], B[cnt_B])
        if readtime > k:
            readtime -= min(A[cnt_A], B[cnt_B])
            break
        else:
            if A[cnt_A] <= B[cnt_B]:
                cnt_A += 1
                if cnt_A == n:
                    A.append(time_max)
            else:
                cnt_B += 1
                if cnt_A == n:
                    A.append(time_max)
    print(cnt_A + cnt_B)


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

a_i = 0
b_i = 0
t = 0
count = 0
while t <= K:
    if a_i < len(A) and A[a_i] < B[b_i] and t + A[a_i] <= K:
        t += A[a_i]
        count += 1
        a_i += 1
    elif b_i < len(B) and t + B[b_i] <= K:
        t += B[b_i]
        count += 1
        b_i += 1
    else:
        break
print(count)

Submission status: Runtime Error

Solution code:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
count = 0
numa = 0
numb = 0
while True:
    if numa < len(A) and numb < len(B):#リストの番号をどちらも指定できる
        if A[numa] <= B[numb] and count + A[numa] <= K:#AがB以下
            count += A[numb]
            numa += 1
        elif A[numa] > B[numb] and count + B[numb] <= K:#AがBより大きい
            count += B[numb]
            numb +=1
        else:#これ以上本を取り除けない
            break
    
    elif numa >= len(A) and numb < len(B):#Aだけのリストが終了
        if count + B[numb]<=K:
            count += B[numb]
            numb += 1
        else:
            break
    elif numa < len(A) and numb >= len(B):#Bだけのリストが終了
        if count + A[numa]<=K:
            count += B[numa]
            numa += 1
        else:
            break
    else:#リストのどちらも終了
        break

print(numa+numb)

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

read = 0
i, j = 0, 0
while(i<len(a) and j<len(b)):
    if a[i]<b[j]:
        k -= a[i]
        i += 1
    else:
        k -= b[j]
        j += 1
    if k<0:
        break
    read += 1

if k > 0 or k == 0:
    if i==len(a):
        while(j < len(b)):
            k -= b[j]
            j += 1
            if k<0:
                break
            read += 1
    elif j==len(b):
        while(i < len(a)):
            k -= a[i]
            i += 1
            if k<0:
                break
            raed += 1

print(read)

Submission status: Runtime Error

Solution code:
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

N, M, K = MAP()
A = LIST()
B = LIST()


def dfs(AorB, A_idx, B_idx, time_left, n_book):
    if AorB == "A":
        if A_idx == N:
            return n_book
        if A[A_idx] > time_left:
            return n_book
        time_left -= A[A_idx]
        A_idx += 1
        n_book += 1

    else:
        if B_idx == M:
            return n_book
        if B[B_idx] > time_left:
            return n_book
        time_left -= B[B_idx]
        B_idx += 1
        n_book += 1


    n_book = max(
        dfs("A", A_idx, B_idx, time_left, n_book),
        dfs("B", A_idx, B_idx, time_left, n_book),
        )
    return n_book

print(max(dfs("A", 0, 0, K, 0), dfs("B", 0, 0, K, 0)))

Submission status: Runtime Error

Solution code:
from collections import deque
N, M, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
if sum(A) + sum(B) <= K:
    print(len(A)+len(B))
else:
    if A[-1] < B[0]:
        ans = len(A)
        B = deque(B)
        time = 0
        while time < K - sum(A):
            time += B[0]
            ans += 1
            B.popleft()
        print(ans)
    elif B[-1] < A[0]:
        ans = len(B)
        A = deque(A)
        time = 0
        while time < K - sum(B):
            time += A[0]
            ans += 1
            A.popleft()
        print(ans)
    else:
        A = deque(A)
        B = deque(B)
        time = 0
        ans = 0
        while time < K:
            if A[0] <= B[0]:
                time += A[0]
                ans += 1
                A.popleft()
            else:
                time += B[0]
                ans += 1
                B.popleft()
        print(ans-1)

Submission status: Runtime Error

Solution code:
n,m , k = [int(x) for x in input().strip().split()]

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

dp = [[-1 for j in range(m+1)] for i in range(n+1)]
def solve(i,j,t):
    if i==n and j==m:
        return 0

    if dp[i][j]!=-1:
        return dp[i][j]

    if i==n:
        if t+b[j]<k:
            dp[i][j] = 1+solve(i,j+1,t+b[j])
        elif t+b[j]==k:
            dp[i][j] = 1
        else:
            dp[i][j]=0
    elif j==n:
        if t+a[i]<k:
            dp[i][j] = 1+solve(i+1,j,t+a[i])
        elif t+a[i]==k:
            dp[i][j] = 1
        else:
            dp[i][j]=0
    else:
        if t+b[j]<k:
            t1 = 1+solve(i,j+1,t+b[j])
        elif t+b[j]==k:
            t1 = 1
        else:
            t1=0

        if t+a[i]<k:
            t2 = 1+solve(i+1,j,t+a[i])
        elif t+a[i]==k:
            t2 = 1
        else:
            t2=0

        dp[i][j] = max(t1,t2)
    
    return dp[i][j]

print(solve(0,0,0))

Submission status: Runtime Error

Solution code:
m,n,k =map(int,input().split())
ml=list(map(int,input().split()))
nl=list(map(int,input().split()))
tl=ml+nl
tl.sort()
sum=0
count=0
for i in range(len(t1)):
  if sum+t[i]<k:
    sum=sum+t[i]
    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()))

cnt = 0
while(True):
    if len(a) == 0 and len(b) == 0:
        print(cnt)
        exit()

    am = 1001001001
    bm = 1001001001
    if len(a) > 0:
        am = a[0]
    if len(b) > 0:
        bm = b[0]
    
    if am > bm:
        if k >= bm:
            k -= bm
            cnt += 1
            b.pop(0)
        else:
            print(cnt)
            exit()
    elif am < bm:
        if k >= am:
            k -= am
            cnt += 1
            a.pop(0)
        else:
            print(cnt)
            exit()
    else:
        if a[1] > b[1]:
            if k >= bm:
                k -= bm
                cnt += 1
                b.pop(0)
            else:
                print(cnt)
                exit()
        else:
            if k >= am:
                k -= am
                cnt += 1
                a.pop(0)
            else:
                print(cnt)
                exit()

Submission status: Runtime Error

Solution code:
a=input().split(" ")
b=input().split(" ")
c=input().split(" ")
d=0
e=0
f=0
count=0
while int(a[2])>=e and int(a[2])>=b[0]:
    if d<3:
        e=e+int(b[d])
        d=d+1
        count+=1
    elif f<4 and d>=3:
        e=e+int(c[f])
        f=f+1
        count+=1
    else:
        break

print(count)

Submission status: Runtime Error

Solution code:
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
i=0
j=0
time=0
while time<k:
    if A[i]<=B[j]:
        time+=A[i]
        i+=1
    elif A[i]>B[j]:
        time+=B[j]
        j+=1
print(i+j-1)

Submission status: Runtime Error

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

time = 0

for i in range(len(a)):
	for j in range(len(b)):
		time = a[i] + a[j]
		if time > K:
			break:

print(time)

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 = a+b
c.sort()
i = 0
ans = 0
count = 0
if sum(c) <= k:
    print(n+m)
    exit()
if c[0] > k:
    print(0)
    exit() 

while True:
    if a[0] >= b[0]:
        ans += b[0]
        b = b[1:]
    else:
        ans += a[0]
        a = a[1:]
    if ans > k:
        print(count)
        break
    count += 1
    i += 1

Submission status: Runtime Error

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

time = 0
i = 0
j = 0
cnt = 0
a = A[i]
b = B[j]
while(time<K):
    if a<b :
        time += a
        i += 1
        if i >= N:
            a = 99999999999
        else:
            a = A[i]
    else :
        time += b
        j +=1
        if j >= M:
            b = 99999999999
        else:
            b = B[j]
    cnt += 1
    if cnt >=(N+M):
        break
    if time >= K:
        cnt -= 1
        break

print(cnt)

Submission status: Runtime Error

Solution code:
n,m,k = map(int,input().split())
al=list(map(int,input().split()))
bl=list(map(int,input().split()))
if sum(al)+sum(bl)<=k:
  print(n+m)
  exit()
ans = 0
used = 0
indexa = indexb = -1
for i in range(n):
  if used+al[i] <= k:
    used += al[i]
    indexa=i
  else:
    ans += i
    break
for i in range(m):
  if used+bl[i] <= k:
    used += bl[i]
    indexb = i
  else:
    ans += i
    break

tmp = ans
for i in range(indexa,-1,-1):
  used -= al[i]
  tmp -= 1
  while bl[indexb+1]+used <=k:
    used += bl[indexb+1]
    indexb += 1
    tmp += 1
  ans = max(tmp,ans)
print(ans)

Submission status: Runtime Error

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

if sum(a)+sum(b) <= k:
    print(len(a)+len(b))
    exit()

while k >= a[0] or k >= b[0]:
    if len(a)==0:
        k-=b[0]
        ans+=1
        del b[0]
    elif len(b)==0:
        k-=a[0]
        ans+=1
        del a[0]
    elif a[0] < b[0]:
        k-=a[0]
        ans+=1
        del a[0]
    else:
        k-=b[0]
        ans+=1
        del b[0]
print(ans)

Submission status: Runtime Error

Solution code:
n,m,k=map(int,input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
ans = 0
while(k>0):
    if(len(a) == 0 or len(b) == 0):
        if(len(a) == 0 and len(b)==0):
            break        
        elif(len(a) == 0):
            if(k >= b[0]):
                k -= b.pop(0)
                ans += 1
            else:
                break
        elif(len(b) == 0):
            if(k >= a[0]):
                k -= a.pop(0)
                ans += 1
            else:
                break
    else:
        if(a[0]>b[0]):
            if(k >= b[0]): 
                k -= b.pop(0)
                ans +=1
            else:
                break
        else:
            if(k >= a[0]):
                k -= a.pop(0)
                ans += 1
            else:
                break
    print(a,b,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()))

ans = 0
k_list = []

flag = True

while k > 0:
    if len(a) > 0 and a[0] <= b[0]:
        k -= a.pop(0)
        ans += 1
    else:
        k -= b.pop(0)
        ans += 1
    if len(a) == 0 and len(b) == 0:
        flag = False
        break

if flag:
    print(ans-1)
else:
    print(ans)

Submission status: Runtime Error

Solution code:
n, m, k = map(int, input().split())
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
SA = sum(A)
SB = sum(B)

if SA+SB <= k:
    print(len(A) + len(B))
else:
    t = 0
    ai = 0; bi = 0
    while True:
        if bi == m or A[ai] < B[bi]:
            t += A[ai]
            ai += 1
        else:
            t += B[bi]
            bi += 1

        if t >= k:
            break
    print(ai + bi - 1)

Submission status: Runtime Error

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

idxA = idxB = 0
readTime :int = 0
readBooks :int = 0
while readTime < k:
    #if arA[idxA] <= arB[idxB] and idxA < n:
    if idxA < n and arA[idxA] <= arB[idxB]:
        if k < readTime + arA[idxA]:
            break
        readTime += arA[idxA]
        idxA += 1
    else:
        if k < readTime + arB[idxB]:
            break
        readTime += arB[idxB]
        idxB += 1
    readBooks += 1
    if idxA >= n and idxB >= m:
        break

print(readBooks)

Submission status: Runtime Error

Solution code:
n, m, k = map(int, input().split())
alis = list(map(int, input().split()))
blis = list(map(int, input().split()))
su = 0
a = 0
b = 0
while su <= k:
  if alis[a] > blis[b]:
    su += blis[b]
    b += 1
  else:
    su += alis[a]
    a += 1
    
print(a + b - 1)

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()))
for i in li_b:
  li_a.append(i)
li_a.sort()
count=0
while c>=0:

      
    c=c-li_a[count]
    if c<0:
      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()))
t = 0
def search(x, y, t):
    if t > k:
        return x + y - 1
    elif x == n and y == m:
        return x + y
    elif x == n or a[x] > b[y]:
        return search(x, y + 1, t + b[y])
    elif y == m or a[x] < b[y]:
        return search(x + 1, y, t + a[x])
    return max(search(x + 1, y, t + a[x]), search(x, y + 1, t + b[y]))

ans = search(0, 0, t)
print(ans)

Submission status: Runtime Error

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

i,j=0,0
time=0
cnt=0

while time<K and (i<N or j<M):
    if i==N:
        if time+B[j]>K:
            break
        time+=B[j]
        cnt+=1
        j+=1
    elif j==N:
        if time+A[i]>K:
            break
        time+=A[i]
        cnt+=1
        i+=1
    elif A[i]<B[j]:
        if time+A[i]>K:
            break
        time+=A[i]
        cnt+=1
        i+=1
    elif B[j]<A[i]:
        if time+B[j]>K:
            break
        time+=B[j]
        cnt+=1
        j+=1
    else:
        if time+A[i]>K:
            break
        if j==M-1 and i==N-1:
            time+=A[i]
            cnt+=1
            i+=1
        elif j==M-1:
            time+=A[i]
            cnt+=1
            i+=1
        elif i==N-1:
            time+=B[j]
            cnt+=1
            j+=1
        else:
            if A[i+1]<B[j+1]:
                time+=A[i]
                cnt+=1
                i+=1
            elif A[i+1]>B[j+1]:
                time+=B[j]
                cnt+=1
                j+=1
            else:
                time+=A[i]
                cnt+=1
                i+=1
print(cnt)

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((t < k) and (i < z and j < z)):
        if a[i] >= b[j]:
            t += b[j]
            j += 1
            ans += 1
            #print("**")
            #print(t, ans)
        
        if a[i] < b[j]:
            t += a[i]
            i += 1
            ans += 1
            #print("**")
            #print(t, ans)
    
    if z==n:
        for i in range(j, len(b)):
            if t+b[i] <= k:
                ans += 1
                t += b[i]
                #print('YES')
                #print(t, ans)
            else:
                break
                
    if z==m:
        for i in range(i, len(a)):
            if t+a[i] <= k:
                #print('YES')
                ans +=1
                t += a[i]
                #print(t, ans)
            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()))
total = 0
ac = 0
bc = 0
count = 0
while True:
  if k < total:
    break
  count += 1
  if a[ac] < b[bc]:
    total += a[ac]
    ac += 1

  else:
    total += b[bc]
    bc += 1
print(count)

Submission status: Runtime Error

Solution code:
def calcTime(indexA ,indexB,sumTime,co):
    sys.setrecursionlimit(10 ** 9 +1)
    A = 0
    B = 0
    global count
    if indexA+1 < n and sumTime+a[indexA+1] <=k:
        A = calcTime(indexA+1,indexB,sumTime+a[indexA+1],co+1)
        if count < co+1:
            count +=1
    if indexB+1 < m and sumTime+b[indexB+1] <=k:
        B = calcTime(indexA,indexB+1,sumTime+b[indexB+1],co+1)
        if count < co+1:
            count +=1


if __name__ == '__main__':
    n, m,k = map(int, input().split())
    a = [int(i) for i in input().split()]
    b = [int(i) for i in input().split()]
    global count
    count = 0
    calcTime(-1,-1,0,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()))

if K >= sum(A) + sum(B):
    print(N + M)
    exit()

n = []


def read(k, n_books, a, b):
    # print(k, n_books, a, b)
    if len(a) > 0 and k - a[0] >= 0:
        read(k - a[0], n_books+1, a[1:], b)
    if len(b) > 0 and k - b[0] >= 0:
        read(k - b[0], n_books+1, a, b[1:])
    if k - a[0] < 0 and k - b[0] < 0:
        n.append(n_books)


read(K, 0, A, B)
print(max(n))

Submission status: Runtime Error

Solution code:
N,M,K = map(int, input().split())
S = N + M

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

sum = 0

for s in range(S):

    if len(A)==0 or A[0]>B[0]:
        sum=sum+B[0]
        B.pop(0)
    elif len(B)==0 or A[0]<B[0]:
        sum=sum+A[0]
        A.pop(0)
    if K < sum:
        break
else:
    s+=1


print(s)

Submission status: Runtime Error

Solution code:
N,M,K = map(int,input().split())
A = deque(LI())
B = deque(LI())
res = 0
rem = K

for _ in range(N+M):
  if len(A) == 0 and len(B) == 0: break

  if len(A) == 0:
    book = B.popleft()
  elif len(B) == 0:
    book = A.popleft()
  else:
    if A[0] > B[0]:
      book = B.popleft()
    elif A[0] < B[0]:
      book = A.popleft()
    else:
      if len(A) > 1 and len(B) > 1:
        if A[1] > B[1]:
          book = B.popleft()
        else:
          book = A.popleft()
      elif len(A) > 1:
        book = A.popleft()
      else:
        book = B.popleft()

  if rem - book >= 0:
    res += 1
    rem -= book
  else:
    break

print(res)