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
input = sys.stdin.readline

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

a_wa = [0]
max_a_idx = None
for idx, a in enumerate(A):
    a_wa.append(a_wa[-1] + a)

    if a_wa[-1] > K:
        break

max_a_idx = len(a_wa)
b_wa = [0]
max_b_idx = None
for idx, b in enumerate(B):
    b_wa.append(b_wa[-1] + b)

    if b_wa[-1] > K:
        break

max_b_idx = len(b_wa)

if max_a_idx + max_b_idx == 2:
    print(0)
    exit()
elif max_a_idx == 1:
    print(max_b_idx)
    exit()
elif max_b_idx == 1:
    print(max_a_idx + 1)
    exit()

out_num = 0
for a_idx in range(max_a_idx):
    for b_idx in range(max_a_idx+1):
        if a_wa[a_idx] + b_wa[b_idx] <= K:
            out_num = max(out_num, a_idx + b_idx)

print(out_num)

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]
        k -= B[idx_b]
        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 = list(map(int, input().split()))
b_list = list(map(int, input().split()))

n_list=[[0]*k for i in range(m)]
count=0
count_min=0
value=0
for item in a_list :
  value+=item
  count+=1
  current=count

  cure_value=value
  for item2 in b_list :
    if cure_value+item2<=k :
      current+=1
      cure_value+=item2
  count_min=max(count_min,current)


print(count_min)

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()))
time = sum(a_list) + sum(b_list)
a = n - 1
b = m - 1
ans1 = n + m
ans2 = 0

while time > k:
    if b < 0 or a_list[a] > b_list[b]:
        time -= a_list[a]
        a -= 1
    elif a < 0 or a_list[a] <= b_list[b]:
        time -= b_list[b]
        b -= 1
    ans1 -= 1

for i in range(n + m):
    if a_list[a] < b_list[b]:
        time += a_list[a]
        a += 1
    else:
        time += b_list[b]
        b += 1

    if time > k:
        break
    else:
        ans2 += 1

    if a >= n:
        a_list.append(max)
    if b >= m:
        b_list.append(max)

print(max(ans1, ans2))

Submission status: Runtime Error

Solution code:
import sys

readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda: readline().rstrip() # input string
ni = lambda: int(readline().rstrip()) # input int
nm = lambda: map(int, readline().split()) # input multiple int 
nl = lambda: list(map(int, readline().split())) # input multiple int to list

n, m, k = nm()
a = nl()
b = nl()
ans = 0
sum_a = [0]*(n+1)
sum_b = [0]*(m+1)
for i in range(1, n+1):
    sum_a[i] = sum_a[i-1] + a[i-1]
for i in range(1, m+1):
    sum_b[i] = sum_b[i-1] + b[i-1]
ans = 0
bef_j = m
for i in range(n+1):
    if sum_a[i] >= k:
        break
    for j in range(m+1, -1, -1):
        if sum_a[i] + sum_b[j] <= k:
            ans = max(ans, i+j)
            bef_j = j
            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()))
C=0
D=0
E=0
F=0
for i in range(0,K):
    for e in range(0,K):
        i=i+0
        e=e+0
        if C<=K:
            F=C+A[i]
            E=C+B[e]
            if F<=K and E<=K:
                if N>=1 and M==0 and A[i]<=K:
                    C=C+A[i]
                    D=D+1
                    i=i+1
                elif N==0 and M<=1 and B[e]<=K:
                    C=C+B[e]
                    D=D+1
                    e=e+1
                elif N>=1 and M>=1 and A[i]<=K and B[e]>K:
                    C=C+A[i]
                    D=D+1
                    i=i+1
                elif N>=1 and M>=1 and A[i]>K and B[e]<=K:
                    C=C+B[e]
                    D=D+1
                    e=e+1
                elif N>=1 and M>=1 and A[i]<=K and B[e]<=K:
                    if A[i]<=B[e]:
                        C=C+A[i]
                        D=D+1
                        i=i+1
                    elif A[i]>=B[e]:
                        C=C+B[e]
                        D=D+1
                        e=e+1
                    else:
                        break
                else:
                    break
            elif F<=K and E>K:
                if N>=1:
                    C=C+A[i]
                    D=D+1
                    i=i+1
                else:
                    break
            elif F>K and E<=K:
                if M>=1:
                    C=C+B[i]
                    D=D+1
                    e=e+1
                else:
                    break
            else:
                break
        else:
            break
            
print(D)

Submission status: Runtime Error

Solution code:
import collections as deque
N, M, K = map(int, input().split())
A = deque.deque(list(map(int, input().split())))
B = deque.deque(list(map(int, input().split())))
i, j = 0, 0
read = []

if K >= sum(A) + sum(B):
    print(len(A) + len(B))

while sum(read) <= K:
    if A and B:
        if A[0] >= B[0]:
            if sum(read) + B[0] <= K:
                read.append(B.popleft())
            else:
                break
        else:
            if sum(read) + A[0] <= K:
                read.append(A.popleft())
            else:
                break
    else:
        if len(B) > 0:
            while sum(read) <= K:
                if sum(read) + B[0] <= K:
                    read.append(B.popleft())
                else:
                    break
            break
        else:
            while sum(read) <= K:
                if sum(read) + A[0] <= K:
                    read.append(A.popleft())
                else:
                    break
            break


print(len(read))

Submission status: Runtime Error

Solution code:
def ABC172_C():
    import sys
    sys.setrecursionlimit(4100000)

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

    minamo = []
    def saiki(i,j,sum,mx):
        if sum >= k:
            mx = min(i+j,mx)
            return mx

        if i+j >= mx:
            return mx

        if i+1 <= n:
            if a[i] > k:
                return 0
            mx = saiki(i+1,j,sum+a[i],mx)
        if j+1 <= m:
            if b[i] > k:
                return 0
            mx = saiki(i,j+1,sum+b[j],mx)

        return mx

    mls = saiki(0,0,0,pow(10,5))
    print(mls)

ABC172_C()

Submission status: Runtime Error

Solution code:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
C = A + B
for i in range(len(C)):
  C[i] = min(A[i],B[i])
  
for i in range(len(C)):
  if K => C[i]:
    K -= C[i]
    ans +=1
  else:
    break
print(ans)

Submission status: Runtime Error

Solution code:
from itertools import zip_longest
N, M, K = map(int,input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
final_list = []
sum = 0
i = 0

for value in (i for pair in zip_longest(A, B) for i in pair if i):
    if value > 0:
        final_list.append(value)
    else:
        final_list.insert(0, value)

for i in final_list:
        sum=sum+i
        if sum>limit:
            print(i)
        else:
            print(i)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

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

if sum(a)+sum(b) <= k:
    print(len(a)+len(b))
else:
    time = 0
    count = 0
    for i in range(n+m):
        if time+min(a[0], b[0]) > k:
            break
        if a[0] <= b[0]:
            time += a[0]
            count+= 1
            a.pop(0)
        else:
            time += b[0]
            count+= 1
            b.pop(0)
    print(count)

Submission status: Runtime Error

Solution code:
N,M,K = input().split()
N= int(N)
M=int(M)
K=int(K)
A = list(map(int,input().split()))
B = list(map(int,input().split()))
time = 0
count = 0
ai = 0
bi = 0
for a in A:
    time += a
    ai += 1
    count += 1
    if time > K:
        ai -= 1
        count -= 1
        break

ans = count
while (True):
    time += B[bi]
    if time > K:
        time -= B[bi]
        time -= A[ai]
        count -= 1
        ai -= 1
        if ai < 0:
            break
    if time <= K:
        count += 1
        bi += 1
        if count > ans:
            ans = count
        if bi >= M:
            break

print(ans)

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:
import numpy as np

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

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

#print(b_li)

ans = 0
for i,book in enumerate(a_sum):
  if book <= k:
    if i+1+b_li[k-book] > ans:
      ans = i+1+b_li[k-book]

print(ans)

Submission status: Runtime Error

Solution code:
sec = list(map(int,input().split()))
sec = sec[2]
a_list = list(input().split())
b_list = list(input().split())
ans = 0
bfans = 0
i = 0
j = 0

while sec >= ans or (i+j) == len(a_list+b_list)-1:
    print(i,j)
    if a_list[i] > b_list[j]:
        if i == len(a_list):
            bfans +=1
            j +=1 
        else:            
         bfans +=1
         ans += int(a_list[i])
         i += 1
    else:
        if j == len(b_list):
            bfans +=1
            i +=1
        else:
         bfnas +=1
         ans += int(b_list[j])
         j += 1   
print(int(bfans -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()))
ans=0
ati=[0]
bti=[0]
for i in range(n):
  ati.append(ati[i]+a[i])
for i in range(m):
  bti.append(bti[i]+b[i])
x=0
y=0
while 1:
  if x==m and ati[x]+bti[y+1]<k:
    y+=1
  elif y==n and ati[x+1]+bti[y]<k:
    x+=1
  elif  ati[x+1]>bti[y+1]:
    y+=1
  elif y<n-1 and x<m-1 and ati[x+1]<bti[y+1]:
    x+=1
  else:
    ans=x+y
    break
  z=ati[x]+bti[y]
  if z>k:
    ans=x+y-1
    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()))

c = 0
i = 0
j = 0
time = 0
L = []
while i <= n-1 and j <= m-1:
	if a[i] > b[j]:
		L.append(b[j])
		j += 1
		pass
	if a[i] < b[j]:
		L.append(a[i])
		i += 1
		pass
	if i == n-1 and j <= m-1:
		L.append(b[j])
		j += 1
		pass
	if j == m-1 and i <= n-1:
		L.append(a[i])
		i += 1
		pass

while time <= k:
	time += L[c]
	c += 1
	if c == len(L):
		c += 1
		break
if time <= k:
	print(c)
else:
	print(c-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
i=1+1
if K<=0:
    print(i)

Submission status: Runtime Error

Solution code:
import sys
import math
import heapq
from collections import defaultdict, deque
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
def r():
    return int(input())
def rm():
    return map(int,input().split())
def rl():
    return list(map(int,input().split()))

'''C Tsundoku v2
def count(i,n,j,m,a,b,k):
    if k<0:
        return -1
    if i==n and j==m:
        return 0
    if i==n:
        if b[j]<=k:
            return 1+count(i,n,j+1,m,a,b,k-b[j])
        return 0
    if j==m:
        if a[i]<=k:
            return 1+count(i+1,n,j,m,a,b,k-a[i])
        return 0
    return max(1+count(i,n,j+1,m,a,b,k-b[j]),1+count(i+1,n,j,m,a,b,k-a[i]))

n,m,k=rm()
a=rl()
b=rl()
i=0;j=0;
print(count(i,n,j,m,a,b,k))'''

'''C M1'''
n,m,k=rm()
a=rl()
b=rl()
i=0;j=0;cnt=0;cnt1=0;cnt2=0;la=n;lb=m;k1=k;k2=k
while i<la and k1>0:
    if a[i]<=k1:
        cnt1+=1
        k1-=a[i]
        i+=1
    else:
        break
i=0;j=0
while j<lb and k2>0:
    if a[j]<=k2:
        cnt2+=1
        k2-=a[j]
        j+=1
    else:
        break
i=0;j=0
while (i<la or j<lb) and k>0:
    if i==la:
        if b[j]<=k:
            cnt+=1
            k-=b[j]
            j+=1
        else:
            break
    elif j==lb:
        if a[i]<=k:
            cnt+=1
            k-=a[i]
            i+=1
        else:
            break
    elif a[i]<=b[j]:
        if a[i]<=k:
            k-=a[i]
            cnt+=1
            i+=1
        else:
            break
    else:
        if b[j]<=k:
            k-=b[j]
            cnt+=1
            j+=1
        else:
            break
print(max(cnt,cnt1,cnt2))

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
            if 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:
N,M,K = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
subseqA = [0] # i th element is sum of first i books
subseqB = [0]
for elem in a:
    subseqA.append(subseqA[-1]+elem)
for elem in b:
    subseqB.append(subseqB[-1]+elem)
maxBooks = 0
curABooks = 0
curBBooks = 0
for i in range(N+1):
    if K < subseqA[i]:
        curABooks = i - 1
        maxBooks = i - 1
        break
for i in range(curABooks,-1,-1):
    for j in range(curBBooks + 1,M+1):
        if subseqA[i] + subseqB[j] > K:
            curBBooks = j - 1
            break
    if subseq[i] + subseqB[M] > K:
        curBBooks = M
    if i + curBBooks > maxBooks:
        maxBooks = i + curBBooks
print(maxBooks)

Submission status: Runtime Error

Solution code:
input1 = list(map(int, input().split()))
N = input1[0]
M = input1[1]
K = input1[2]

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

num_a = 0
num_b = 0

book_count = 0
time_count = 0

flag_a = True
flag_b = True

tmp = 0

def timecheck(time_count):
    return(True if time_count < K else False )


while (num_a < N and num_b < M):
    if(A[num_a] < B[num_b]):
        time_count += A[num_a]
        num_a += 1

    elif(A[num_a] == B[num_b]):
        myflag = True
        i = 1
        while(myflag):
            # print(num_a)
            if(num_a + i == N or num_b + i ==M):
                # print(i)
                # if(N >= M):
                time_count += A[num_a]
                num_a += 1
                # else:
                #     time_count += B[num_b]
                #     num_b += 1
            elif(A[num_a + i] == B[num_b + i]):
                i += 1
            else:
                myflag = False
                if(A[num_a + i] < B[num_b + i]):
                    time_count += A[num_a]
                    num_a += 1
                else:
                    time_count += B[num_b]
                    num_b += 1


    else:
        time_count += B[num_b]
        num_b += 1
    
    if(timecheck(time_count) == False):
        break




while (timecheck(time_count) == True and num_a < N):
    time_count += A[num_a]
    num_a += 1
    if(timecheck(time_count) == False):
        break

while (timecheck(time_count) == True and num_b < M):
    time_count += B[num_b]
    num_b += 1
    if(timecheck(time_count) == False):
        break

print(num_a + num_b - 1 if time_count > K else num_a + num_b)

Submission status: Runtime Error

Solution code:
n=i[0]
m=i[1]
k=i[2]
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a=b=0 #それぞれの読んだ数
cal=0 #読んだ時間
if max(A)>pow(10,9) or max(B)>pow(10,9):
    print(0)
else:
    while True:
        if a!=n and b!=m:
            if A[a]<=B[b]:
                cal+=A[a]
                if cal>k:
                    break
                a+=1
            elif B[b]<A[a]:
                cal+=B[b]
                if cal>k:
                    break
                b+=1
        elif a==n and b==m:
            break
        elif a==n and b!=m:
            cal+=B[b]
            if cal>k:
                break
            b+=1
        elif a!=n and b==m:
            cal+=A[a]
            if cal>k:
                break
            a+=1
    print(a+b)

Submission status: Runtime Error

Solution code:
#ABC172C
n, m, k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
i = 1 #Aの掘り具合
j = 1 #Bの掘り具合
ans = 0 #読んだ本の冊数
while k > 0:
    if A[i-1] > B[j-1] and B[j-1] <= k:
        k = k - B[j-1]
        ans = ans + 1
        j = j + 1
    elif A[i-1] < B[j-1] and A[i-1] <= k:
        k = k - A[i-1]
        ans = ans + 1
        i = i + 1
    if j == len(B):
        B[j-1] = 10**9
    if i == len(A):
        A[i-1] = 10**9
    if i  == len(A) and j  == len(B):
        break
print(ans)

Submission status: Runtime Error

Solution code:


def main():
    n, m, k = map(int, input().split())
    aa = list(map(int, input().split()))
    bb = list(map(int, input().split()))
    ans = []
    time_sum = 0
    for i in range(n):
        for j in range(1, m):
            time_sum = sum(aa[:i]) + sum(bb[:j])
            if time_sum <= k:
                ans.append(i+j)

    if(len(ans) == 1):
        return ans[0]
    else:
        return max(ans)


if __name__ == '__main__':
    ans = main()
    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()))
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==M:
      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 = list(map(int, input().split()))
B = list(map(int, input().split()))
sum = 0
count = 0
i = 0
j = 0
while sum <= K:
  if not A and not B:
    break
  elif A[0] > K and B[0] > K:
    break
  elif not A:
    sum += B[0]
    B.pop(0)
  elif not B:
    sum += A[0]
    A.pop(0)
  elif A[0] >= B[0]:
    sum += A[0]
    A.pop(0)
  elif B[0] > A[0]:
    sum += B[0]
    B.pop(0)
    count += 1

print(count)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**6)
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.append(99999)
B.append(99999)
Sum = 0
i = 0
j = 0
while True:
  if A[i] < B[j] and Sum + A[i] <= K:
    Sum += A[i]
    i += 1
  elif A[i] > B[j] and Sum + B[j] <= K:
    Sum += B[j]
    j += 1
  elif A[i] = B[j] and Sum + A[i] <= K:
    if A[i+1] >= B[j+1]:
      Sum += B[j]
      j += 1
    elif
    else:
      Sum += A[i]
      i += 1
  else:
    break
print(i + j)

Submission status: Runtime Error

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

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

if sum(A) + sum(B) <= K:
    print(len(A)+len(B))
else:
    ans = 0
    count = 0
    j = 0
    for i in range(0,len(A)):
        if A[i] <= B[j]:
            ans += A[i]
            #print(A[i])
            #print(ans)
            #print('1')
            if ans >= K: 
                break
            else: 
                count += 1
        elif A[i] >= B[j]:
            ans += B[j]
            j += 1
            #print(B[j])
            #print(ans)
            #print('2')
            if ans >= K: 
                break
            else:
                ans += A[i]
                count += 2
            

    #print(ans)    
    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
ANS = 0

for i in range(len(A)):
    count += A[i]
    if count >= K:
        del A[i-1:]
        count=0
        break

for i in range(len(B)):
    count += B[i]
    if count >= K:
        del B[i-1:]
        count=0
        break

count = sum(A) + sum(B)




while count > K:
    if A[-1] > B[-1]:
        count -= A[-1]
        del A[-1]
    else:
        count -= B[-1]
        del B[-1]
        
print(len(A) + len(B) +1)

Submission status: Runtime Error

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

acs = [0]*(N+1)
for i in range(N):
    acs[i+1] = acs[i]+A[i]
    if acs[i+1] > K:
        A = A[:i]
        acs = acs[:i]
        break
A = A[::-1]

bcs = [0]*(M+1)
for i in range(M):
    bcs[i+1] = bcs[i]+B[i]
    if bcs[i+1] > K:
        B = B[:i]
        bcs = bcs[:i]
        break
B = B[::-1]

lng = []
srt = []
if len(acs) >= len(bcs):
    lng = A
    srt = bcs[::]
else:
    lng = B
    srt = acs[::]

lcs = [0]*(len(lng)+1)
lcs[0] = K-sum(lng)
for i in range(len(lng)):
    lcs[i+1] = lcs[i]+lng[i]
lng = lcs

sidx = 0
if len(srt)>0:
    for i in range(len(srt)):
        if srt[i] < lng[i]: sidx = i
lidx = 0
if len(lng)>0:
    for i in range(len(lng)):
        if lng[i] < srt[sidx]: lidx = i

print(len(lng)+sidx-lidx-1)

Submission status: Runtime Error

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

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

if sum(a)+sum(b) <= k:
    print(n+m)


else:
    if sum(a) < sum(b):
        small = a
        big = b
    else:
        small = b
        big = a

    # print(sum(small))

    if sum(small) == k:
        print(len(small))


    if sum(small) < k:
        count = 0
        while sum(small) < k:
            small.append(big.pop(0))
            count += 1
        
        print(len(small) + count)

    elif sum(small) > k:
        # print("here")
        while len(small) > 0 and sum(small) > k:
            small.pop(0)
        count = 0
        while len(small) > 0 and sum(small) <= k:
            small.append(big.pop(0))
            if sum(small) > k:
                small.pop()
            count += 1
        print(len(small))
        # print(small)

    


    
# ans = 0
# temp = 0
# for i in range(len(a)):
#     if temp+a[i] <= k:
#         temp+=a[i]
#         ans += 1

#     else:
#         break

# for i in range(len(b)):
#     if temp+b[i] <= k:
#         temp+=b[i]
#         ans += 1

#     else:
#         break

# print(ans)


# ans =0 


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

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


# if len(b)>0:
#     while len(b)>0 and k >= b[0]:
#         k -= b[0]
#         ans += 1
#         b.pop(0)

# elif len(a)>0:
#     while len(a)>0 and k >= a[0]:
#         k -= a[0]
#         ans += 1
#         a.pop(0)

Submission status: Runtime Error

Solution code:
def Tsundoku():

    Num = list(map(int,input().split()))

    value_A = list(map(int,input().split()))
    value_B = list(map(int,input().split()))

    total_num = 0
    total_num = count(Num, value_A, value_B)

    print(total_num)

def count(Num, value_A, value_B):
    total_time = 0
    total_num = 0
    
    numA = 0
    numB = 0
    
    if value_A[numA] < Num[2] or value_B[numB] < Num[2]:
    
        while (total_time < Num[2]) or (numA + numB < total_num):
    
            if (len(value_A) == numA and len(value_B) == numB):
                return total_num
            
            elif len(value_B) != numB and len(value_A) != numA and value_A[numA] > value_B[numB] and Num[2] > total_time + value_A[numA]:
                total_time = total_time + value_B[numB]
                numB = numB + 1
                total_num = total_num + 1
                print('a1')
                
            elif len(value_A) != numA and len(value_B) != numB and value_A[numA] <= value_B[numB] and Num[2] > total_time + value_B[numB]:
                total_time = total_time + value_A[numA]
                numA = numA + 1
                total_num = total_num + 1            
                print('a2')            
        
            elif len(value_A) == numA and Num[2] > total_time + value_B[numB]:
                total_time = total_time + value_B[numB]
                numB = numB + 1
                total_num = total_num + 1
                print('a3')
                
            elif len(value_B) != numB and Num[2] > total_time + value_A[numA]:
                total_time = total_time + value_A[numA]
                numA = numA + 1
                total_num = total_num + 1
                print('a4')


        return total_num

    else:
        return total_num


if __name__ == '__main__':
    Tsundoku()

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_A=0
sum_B=0
for i in range(min(N,M)):
    sum_A +=A[i]
    sum_B +=B[i]
    if sum_A>K:
        del A[i:]
    if sum_B>K:
        del B[i:]
    if sum_A>K and sum_A>K:
        break
while sum(A)+sum(B)>K:
    if A[-1]>B[-1]:
        del A[-1]
    elif A[-1]<B[-1]:
        del B[-1]
    elif A[-1] == B[-1]:
        del A[-1]
        del B[-1]
        if sum(A)+sum(B)<=K:
            A.append(1)
print(len(A)+len(B))

Submission status: Runtime Error

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

n_list=[[0]*k for i in range(m)]
count=0
count_min=0
value=0
for item in a_list :
  value+=item
  count+=1
  current=count
  
  cure_value=value
  for item2 in b_list :
    if cure_value+item2<=k :
      current+=1
      cure_value+=item2
  count_min=max(count_min,current)
  

print(count_min)

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