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:
n,m,k=map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

ai=0
bi=0
time=0

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


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

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

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

Submission status: Runtime Error

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

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]
            if ans >= K: 
                break
            else: 
                count += 1
        elif A[i] >= B[j]:
            ans += B[j] + A[i]
            j += 1
            if ans >= K: 
                break
            else:
                count += 2
    print(count)

Submission status: Runtime Error

Solution code:
from collections import deque
n, m, k = map(int, input().split())

a = deque(map(int, input().split()))
b = deque(map(int, input().split()))

dp = [0] * (n+m)

for i in range(1, n+m):
    if len(a)+len(b)>0:
        if len(a)>0:
            ai = a.popleft()
        if len(a)>0:
            bi = b.popleft()
        if min(ai, bi) + dp[i-1] <= k:
            dp[i] = min(ai, bi) + dp[i-1]
        else:
            print(i-1)
            exit()
        if ai > bi:
            a.appendleft(ai)
        else:
            b.appendleft(bi)
else:
    print(n+m)

#ai == biのときどうするの？

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

tot = 0
count = 0

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

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

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

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


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




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

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

Submission status: Runtime Error

Solution code:
import bisect
import numpy

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

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

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

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

Submission status: Runtime Error

Solution code:
desk_book_minute = input().split()
lst = []
book_time_A = input().split()
book_time_B = input().split()
c = sorted(book_time_A + book_time_B)
total = 0
i = 0
while total <= int(desk_book_minute[2]):
    total = int(c[i]) + int(c[i+1])
    i += 1
print(i)

Submission status: Runtime Error

Solution code:
import sys
import functools
from collections import deque

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

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


ans = [0, 0, 0]

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

ans = max(L)
print(ans)

Submission status: Runtime Error

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

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





# for i in range(3):
#     box = []
# # 合計がK超えたら終了
#     if sum_on < K:
#         box.append(A[i])
#         box.append(B[i])
#         # print(box)
#         #最小値をsum_onに足していく
#         min_box = min(box)
#         sum_on += min_box
#         # print(sum_on)
#         count += 1
#         continue
#     else:
#         break
# print(count)






"""
sum_on = 0
count = 0
for i in range(0,10):
    box = []
# 合計がK超えたら終了
    if sum_on < K:
    else:
        box.append(A[i])
        box.append(B[i])
        i += 1
        # print(box)
        #最小値をsum_onに足していく
        min_box = min(box)
        sum_on += min_box
        # print(sum_on)
        count += 1
        continue
    break

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()))
nb = 0
ai=0
bi=0
def read(a,b,K):
  nb = 0
  ai=0
  bi=0
  while K>0:
    if a[ai]>b[bi]:
        K-=b[bi]
        nb+=1
        bi+=1
    elif a[ai]<b[bi]:
        K-=a[ai]
        nb+=1
        ai+=1
    else:
        nb+=1
        read(a[ai+1],bi[bi+1])
  return nb-1
print(read(A,B,K))

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 mx
            mx = saiki(i+1,j,sum+a[i],mx)
        if j+1 <= m:
            if b[i] > k:
                return mx
            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:
import numpy as np

N, M, K = map(int, input().split())
A = input().split()
B = input().split()
for i in range(len(A)):
  A[i] = int(A[i])
for i in range(len(B)):
  B[i] = int(B[i])
A_cumsum = np.array(A).cumsum()
B_cumsum = np.array(B).cumsum()
max_count = 0
max_j = 0
for i in range(M):
  if B_cumsum[i] <= K and max_count <= B_cumsum[i]:
    max_count = i + 1
  else:
    break
for i in range(N):
  if A_cumsum[i] <= K and max_count <= A_cumsum[i]:
    max_count = i + 1
  else:
    break
for i in range(N):
  if A_cumsum[i] > K:
    break
  elif A_cumsum[i] + B_cumsum[j] > K:
    for j in range(j):
      if A_cumsum[i] + B_cumsum[j] <= K and max_count <= A_cumsum[i] + B_cumsum[j]:
        max_count = i + j + 2
        max_j=j
      else:
        break
  else:
    for j in range(j, M)[::-1]:
      if A_cumsum[i] + B_cumsum[j] <= K and max_count <= A_cumsum[i] + B_cumsum[j]:
        max_count = i + j + 2
        max_j=j
      else:
        break
    
print(max_count)

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()))
    time_sum = 0
    for i in range(n):
        for j in range(1, m):
            time_sum = aa[:i] + 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()))

A = sorted(a)
B = sorted(b)

result = 0

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

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

print(result)

Submission status: Runtime Error

Solution code:
from sys import stdin
An, Bn, t = [int(x) for x in stdin.readline().rstrip().split()]

A = [int(x) for x in stdin.readline().rstrip().split()]
B = [int(x) for x in stdin.readline().rstrip().split()]

idxA = idxB = cnt = 0

for i in range(An + Bn):
	if t < 0 : break



	if An > idxA :
		calc = t -= A[idxA]
		if calc < 0 : 
			idxA += 1
			continue
		t -= A[idxA]
		cnt += 1
		idxA += 1


	if Bn > idxB :
		calc = t -= B[idxB]
		if calc < 0 :
			idxB += 1
			continue
		t -= B[idxB]
		cnt += 1
		idxB += 1

print(cnt)

Submission status: Runtime Error

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

al=input()
al2=al.split()
for n in range(M):
    al2[n] = int(al2[n])

bl=input()
bl2=bl.split()
for n in range(N):
    bl2[n] = int(bl2[n])

count=0

ai=0
bi=0

aflag,bflag=0,0

while 1:
    if al2[ai] <= bl2[bi] and al2[ai] <= K and aflag != 1:
        K = K-al2[ai]
        if ai == M:
            aflag=1
        else:
            ai+=1
        count+=1
        

    elif al2[ai] > bl2[bi] and bl2[bi] <= K and bflag != 1:
        K = K-bl2[bi]
        if bi == N:
            bflag=1
        else:
            bi+=1
        count+=1
    else:
        break

print(count)

Submission status: Runtime Error

Solution code:
n = int(input())
ans = 0
for i in range(1,n+1):
  tmp = int(n/i)
  ans += i * tmp * (tmp + 1)

print(int(ans/2))

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 k < 0:
        return False

    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

    return True

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

Submission status: Runtime Error

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

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

    asum = [0]*(n+1)
    bsum = [0]*(m+1)

    for i in range(n):
        asum[i+1] = asum[i] + a[i]

    for i in range(m):
        bsum[i+1] = bsum[i] + b[i]

    cnt = 0
    t = 0
    res = 0

    bb = 0
    for i in range(m):
        while bb < m and asum[i] + bsum[bb+1] <= k:
            cnt += 1
            t += bsum[bb+1] - bsum[bb]
            bb += 1

        res += (bb - i)

        if bb == i:
            bb += 1
        else:
            t -= asum[i]
            cnt -= 1

    print(res)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0
aindex=n+1
bindex=m+1
acumsum = [0]
bcumsum = [0]

ab =0
for aa in range(n):
  ab += a[aa]
  acumsum.append(ab)# = ab
  if ab>k:
    aindex= aa
    break

ab =0
for bb in range(m):
  ab += b[bb]
  bcumsum.append(ab)
  if ab>k:
    bindex= bb
    break


from bisect import bisect_left
for i in range(aindex+1):
  j = bisect_left(bcumsum, k-acumsum[i])-1
  ans = max(ans, i+j)
print(ans)

Submission status: Runtime Error

Solution code:
from sys import exit
from collections import deque
# import copy
# import numpy as np
# from collections import deque

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

cnt = 0

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

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

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

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
time = 0
acount = 0
bcount = 0
while time <= k and ans <= m+n:
    if ans == m+n :
        ans += 1
    elif acount == n-1 :
        time += b[bcount]
        bcount += 1
        ans += 1
    elif bcount == m-1 :
        time += a[acount]
        acount += 1
        ans += 1
    elif a[acount] < b[bcount] :
        time += a[acount]
        acount += 1
        ans += 1
    elif a[acount] > b[bcount] :
        time += b[bcount]
        bcount += 1
        ans += 1
    elif a[acount] == b[bcount] :
        if a[acount+1] < b[bcount+1] :
            time += a[acount]
            acount += 1
            ans += 1
        else :
            time += b[bcount]
            bcount += 1
            ans += 1

print(ans-1)

Submission status: Runtime Error

Solution code:
N,M,K = map(int,input().split())
A = map(int,input().split())
B = map(int,input().split())
tt = 0
a = 0
b = 0
if (K >= (sum(A)+sum(B))):
    print(N+M)
elif (A[a]>K)and(B[b]>K):

    print(0)
else:
    while (tt <= K ):

        if (a < N)and (b < M):
            if A[a]>B[b]:
                tt += B[b]
                b += 1
                if tt > K:

                    break
            elif A[a]<B[b]:
                tt += A[a]
                a += 1
                if tt > K:

                    break
            elif (A[a]==B[b])and(a < N-1)and (b < M-1):
                if A[a+1]>B[b+1]:
                    tt += B[b]
                    b += 1
                    if tt > K:

                        break
            elif (A[a]==B[b]and(a == N-1)and (b < M-1):
                tt += B[b]
                b += 1
                if tt > K:

                    break
            else:
                tt += A[a]
                b += 1
                if tt > K:
                    break



        elif (a == N)and (b < M):
            tt += B[b]
            b += 1
            if tt > K:

                break

        elif (a < N)and (b == M):
            tt += A[a]
            a += 1
            if tt > K:

                break

        else:
            break
    print(a + b -1)

Submission status: Runtime Error

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

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

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

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

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

Submission status: Runtime Error

Solution code:
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
Acount = -1
Bcount = -1
tmpA = []
tmpB = []
tmp = 0
for i in range(N):
    tmp += A[i]
    if tmp > K:
        break
    tmpA.append(tmp)
tmp = 0
for i in range(M):
    tmp += B[i]
    if tmp > K:
        break
    tmpB.append(tmp)

if len(tmpA) > 0 and len(tmpB) > 0:
    res = 0
    Bcount = -1
    Acount = len(tmpA) - 1
    while Acount > -1 and Bcount < M:
        for i in range(max(Bcount, 0), M):
            if tmpA[Acount] + tmpB[i] > K:
                break
            Bcount = i
        tmpRes = Acount + Bcount + 2 if Bcount > -1 else Acount + 1
        if res < tmpRes:
            res = tmpRes
        Acount -= 1
    print(res)
elif len(tmpA) > 0:
    print(len(tmpA))
elif len(tmpB) > 0:
    print(len(tmpB))
else:
    print(0)

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

from collections import deque

a = deque(a)
b = deque(b)

ans = 0
time = k

while time >= 0:
    if a and b:
        tmp_a = time-a[0]
        tmp_b = time-b[0]
        if tmp_a >= 0 and tmp_b >= 0 and a[0] <= b[0]:
            time -= a[0]
            a.popleft()
            ans += 1
        elif tmp_a >= 0 and tmp_b >= 0 and b[0] < a[0]:
            time -= b[0]
            b.popleft()
            ans += 1
        elif tmp_a >= 0:
            time -= a[0]
            a.popleft()
            ans += 1
        elif tmp_b >= 0:
            time -= b[0]
            b.popleft()
            ans += 1
        else:
            break
    elif a:
        tmp_a = time-a[0]
        if tmp_a >= 0:
            time -= a[0]
            a.popleft()
            ans += 1
        else:
            break
    elif b:
        tmp_b = time-b[0]
        if tmp_b >= 0:
            time -= b[0]
            b.popleft()
            ans += 1
        else:
            break
    else:
        break
    print(a,b,ans)

print(ans)

Submission status: Runtime Error

Solution code:
from collections import deque
n, m, k = map(int,input().split())
tmpA = list(map(int,input().split()))
tmpB = list(map(int,input().split()))
A = [tmpA[0]]
B = [tmpB[0]]
for i in range(1, n):
    tmp = A[i-1] + tmpA[i]
    if tmp > k:
        break
    else:
        A.append(tmp)
for i in range(1, m):
    tmp = B[i-1] + tmpB[i]
    if tmp > k:
        break
    else:
        B.append(tmp)

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

Submission status: Runtime Error

Solution code:
    s = [input() for i in range(3)]
    list1 = list(map(int, s[0].split()))
    n = list1[0]
    m = list1[1]
    k = list1[2]
     
    list2 = list(map(int, s[1].split()))
    list3 = list(map(int, s[2].split()))
     
    counter_l1 = 0
    counter_l2 = 0
     
    for i in range(n+m):
        if counter_l1 < n and counter_l2 < m:
            if list2[counter_l1] < list3[counter_l2]:
                k = k - list2[counter_l1]
                if k < 0:
                    break
                if k == 0:
                    counter_l1 +=1
                    break
                counter_l1 +=1
                continue
            if list2[counter_l1] >= list3[counter_l2]:
                k = k - list3[counter_l2]
                if k < 0:
                    break
                if k == 0:
                    counter_l1 +=1
                    break
                counter_l2 +=1
        else:
            if counter_l1 >= n:
                k = k - list3[counter_l2]
                if k < 0:
                    break
                if k == 0:
                    counter_l1 +=1
                    break
                counter_l2 +=1
            if counter_l2 >= m:
                k = k - list2[counter_l1]
                if k < 0:
                    break
                if k == 0:
                    counter_l1 +=1
                    break
                counter_l1 +=1
    print(counter_l1+counter_l2)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
book = list(map(int, input().split()))
Nminute = list(map(int, input().split()))
Mminute = list(map(int, input().split()))

total = 0

for i in range(200000):
  book[2] >= Nminute[i] and Mminute[i]:
  book[2] - max(Nminute[i],Mminute[i])
  total += 1
else:
  print(total)

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

print(count)

Submission status: Runtime Error

Solution code:
import numpy as np
from collections import deque
def main():
    N, M, K = map(int, input().split())
    A = deque(list(map(int, input().split())))
    B = deque(list(map(int, input().split())))
    
    cost = K
    count = 0
    while True:
        if len(A) ==0 and len(B) == 0:
            break
        elif len(A) == 0:
            cost -= B.popleft()
        elif len(B) == 0:
            cost -= A.popleft()

        else:
            a = A[0] + A[1]
            b = B[0]
            if a < b:
                cost -= A.popleft()
            else:
                cost -= B.popleft()

        if cost < 0:
            break
        count += 1
    
    print(count)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

if kotei>=sum(a):
  cnt+=len(a)
else:
  x=kotei
  i=0
  while x>=0:
    x-=a[i]
    i+=1
    cnt+=1
  n=i
  ans=max(ans,cnt-1)

for j in range(n):
  i=0
  x+=a[n-1-j]
  cnt-=1
  while x>=0:
    x-=b[i]
    i+=1
    cnt+=1
  ans=max(ans,cnt-1)
  
print(ans)

Submission status: Runtime Error

Solution code:
    s = [input() for i in range(3)]
    list1 = list(map(int, s[0].split()))
    n = list1[0]
    m = list1[1]
    k = list1[2]
     
    list2 = list(map(int, s[1].split()))
    list3 = list(map(int, s[2].split()))
     
    counter_l1 = 0
    counter_l2 = 0
     
    for i in range(n+m):
        if counter_l1 < n and counter_l2 < m:
            if list2[counter_l1] < list3[counter_l2]:
                k = k - list2[counter_l1]
                if k < 0:
                    break
                if k == 0:
                    counter_l1 +=1
                    break
                counter_l1 +=1
            if list2[counter_l1] >= list3[counter_l2]:
                k = k - list3[counter_l2]
                if k < 0:
                    break
                if k == 0:
                    counter_l1 +=1
                    break
                counter_l2 +=1
        else:
            if counter_l1 >= n:
                k = k - list3[counter_l2]
                if k < 0:
                    break
                if k == 0:
                    counter_l1 +=1
                    break
                counter_l2 +=1
            if counter_l2 >= m:
                k = k - list2[counter_l1]
                if k < 0:
                    break
                if k == 0:
                    counter_l1 +=1
                    break
                counter_l1 +=1
    print(counter_l1+counter_l2)