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()))
 
def solve(A, N, B, M, K):
  
  def cumsum(l):
    rt = [0]
    s = 0
    for n in l:
      s += n
      rt.append(s)
    return rt
  
  preA = cumsum(A)
  preB = cumsum(B)
  
  total = N + M
  s, e = 0, total - 1
  
  def can_read(num):
    for i in range(N + 1):
      j = num - i
      if j < (M + 1) and (preA[i] + preB[j]) <= K:
      	return True
    return False

  res = 0
  while s < e:
    mid = s + (e - s) // 2
    can = can_read(mid)
    
    if can:
      res = mid
      s = mid + 1
    else:
      e = mid - 1
  
  return res

res = solve(A, N, B, M, K)
print(res)

Submission status: Runtime Error

Solution code:
N, M, K = map(int, input().split())
A = list(int, input().split())
B = list(int, input().split())
ans = 0
while N > 0 and M > 0:
    C = min(A[0], B[0])
    if C > K:
        break
    K -= C
    if C == A[0]:
        A.pop(0)
        N -= 1
    else:
        B.pop(0)
        M -= 1
    ans += 1
while N > 0:
    if A[0] > K:
        break
    K -= A[0]
    A.pop(0)
    N -= 1
    ans += 1
while M > 0:
    if B[0] > K:
        break
    K -= B[0]
    B.pop(0)
    M -= 1
    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()))
 
def solve(A, N, B, M, K):
  
  def cumsum(l):
    rt = [0]
    s = 0
    for n in l:
      s += n
      rt.append(s)
    return rt
  
  preA = cumsum(A)
  preB = cumsum(B)
  
  total = N + M
  s, e = 0, total - 1
  
  def can_read(num):
    for i in range(N + 1):
      j = num - i - 1
      if j < (M + 1) and (preA[i] + preB[j]) <= K:
      	return True
    return False

  res = 0
  while s < e:
    mid = s + (e - s) // 2
    can = can_read(mid)
    
    if can:
      res = mid
      s = mid + 1
    else:
      e = mid - 1
  
  return res

res = solve(A, N, B, M, K)
print(res)

Submission status: Runtime Error

Solution code:
N, M, K = map(int, input().split())
 
A = input().split()
B = input().split()
 
def solve(A, N, B, M, K):
  
  def cumsum(l):
    rt = []
    s += 0
    for n in l:
      s += n
      rt.append(s)
    return rt
  
  preA = cumsum(A)
  preB = cumsum(B)
  
  total = N + M
  s, e = 0, total - 1
  
  def can_read(num):
    for i in range(N):
      j = num - i - 1
      if j < N and (A[i] + B[j]) <= K
      	return True
    return False
  
  res = 0
  while s < e:
    mid = s + (e - s) / 2
    if can_read(num):
      res = mid
      s = mid + 1
    else:
      e = mid - 1
  
  return res

res = solve(A, N, B, M, K)
print(res)

Submission status: Runtime Error

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))

def binary_search(lis, item):
    low = 0
    high = len(lis) - 1
    inRange = high

    if lis[0] > item:
        return 0

    while low <= high:
        mid = (low + high) //2
        guess1 = lis[mid]
        if mid < inRange:
            guess2 = lis[mid+1]
        else:
            if lis[mid] <= item:
                return len(lis)
            else:
                return len(lis)-1
        if guess1 <= item < guess2:
            return mid+1
        if guess1 > item:
            high = mid-1
        else:
            low = mid+1
    return 0

n,m,k = iim()
a = iil()
cuma = []
if a[0] <= k:
    cuma.append(a[0])
    for i in range(n-1):
        num = cuma[-1]+a[i+1]
        if num > k:
            break
        else:
            cuma.append(num)
#print(len(cuma))
b = iil()
cumb = []
if b[0] <= k:
    cumb.append(b[0])
    for i in range(m-1):
        num = cumb[-1]+b[i+1]
        if num > k:
            break
        else:
            cumb.append(num)
#print(len(cumb))

ans = binary_search(cumb,k)
#print(ans)
if len(cuma) > 0:
    cnt = len(cuma)
    for i,item in enumerate(cuma[::-1]):
        tmp = cnt-i
        res = k-item
        plus = binary_search(cumb,res)
        ans = max(ans,tmp+plus)
print(ans)
#print(ans)

#print(cuma)
#print(cumb)

Submission status: Runtime Error

Solution code:
from queue import deque

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

A = input().split()
B = input().split()

def solve(A, N, B, M, K):
  
  def cumsum(l):
    rt = []
    s += 0
    for n in l:
      s += n
      rt.append(s)
    return rt
  
  preA = cumsum(A)
  preB = cumsum(B)
  
  total = N + M
  s, e = 0, total - 1
  
  def can_read(num):
    for i in range(N):
      j = num - i - 1
      if j < N and (A[i] + B[j]) <= K
      	return True
    return False
  
  res = 0
  while s < e:
    mid = s + (e - s) / 2
    if can_read(num):
      res = mid
      s = mid + 1
    else:
      e = mid - 1
  
  return res

Submission status: Runtime Error

Solution code:
N,M,K=map(int,input().split())
A=[int(x) for x in input().split()]+[10**9]
B=[int(x) for x in input().split()]+[10**9]

c,i,j=0,0,0
while K>0 and (i<N or j<M):
  if K<min(A[i],B[i]):
    break
  c+=1
  if A[i]<B[j]:
    K-=A[i]
    i+=1
  elif B[j]<A[i]:
    K-=B[j]
    j+=1
  else:
    if A[i+1]<=B[j+1]:
      K-=A[i]
      i+=1
    else:
      K-=B[j]
      j+=1

print(c)

Submission status: Runtime Error

Solution code:
N,M,K=map(int,input().split())
A=[int(x) for x in input().split()]+[10**9]
B=[int(x) for x in input().split()]+[10**9]

c,i,j=0,0,0
while K>0 and (i<N or j<M):
  if K==min(K,A[i],B[i]):
    break
  c+=1
  if A[i]<B[j]:
    K-=A[i]
    i+=1
  elif B[j]<A[i]:
    K-=B[j]
    j+=1
  else:
    if A[i+1]<=B[j+1]:
      K-=A[i]
      i+=1
    else:
      K-=B[j]
      j+=1

print(c)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
import math
import collections
from collections import deque 
from functools import reduce

# input = sys.stdin.readline
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a_t, b_t = [0], [0]
for i in range(n):
    a_t.append(a_t[i] + a[i])
for i in range(m):
    b_t.append(b_t[i] + b[i])
ans = 0
j = m
for i in range(n+1):
    if (a[i] > k):
        break
    while(a_t[i] + b_t[j] > k):
        j -= 1
    ans = max(ans, i + j)
print(ans)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
import math
import collections
from collections import deque 
from functools import reduce

# input = sys.stdin.readline
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a_t, b_t = [0], [0]
for i in range(n):
    a_t.append(a_t[i] + a[i])
for i in range(m):
    b_t.append(b_t[i] + b[i])
ans = 0
j = m
for i in range(n):
    if (a[i] > k):
        break
    while(a_t[i] + b_t[j] > k):
        j -= 1
    ans = max(ans, i + j)
print(ans)

Submission status: Runtime Error

Solution code:
from itertools import accumulate
from bisect import bisect

n, m, k = map(int, input().split())
a = [*accumulate(map(int, input().split()), initial=0)]
b = [*accumulate(map(int, input().split()), initial=0)]
ans = 0
for i, x in enumerate(a):
    if x <= k:
        ans = max(i - 1 + bisect(b, k - x))
print(ans)

Submission status: Runtime Error

Solution code:
n, m, time = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
k, kk = 0, 0
c = 0
if time < A[0] and time < B[0]:
    print(0)

if sum(A) + sum(B) <= time:
    print(n+m)

elif sum(A) + sum(B) > time:


    while (time >0):
        if k <= n and kk <=m:
            if A[k] < B[kk]:

                time -= A[k]
                k += 1


            else:

                time -= B[kk]
                kk += 1


        else:
            if k >= n and kk<=m:
                time -= B[kk-1]
                kk +=1

            if kk >= m and k<n:
                time -= A[k-1]
                k += 1
        c += 1

    print(c-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()))
ea=[0]
for i in range(n):
    ea.append(ea[i]+a[i])
eb=[0]
for i in range(m):
    eb.append(eb[i]+b[i])
tb=m
p=0
if n<m:
    ea,eb=eb,ea
    n,m=m,n
for i in range(n+1):
    while ea[i]+eb[tb]>k:
        if tb==0:
            break
        tb-=1
    if ea[i]+eb[tb]<=k:
        p=max(i+tb,p)
print(p)

Submission status: Runtime Error

Solution code:
n,m,l = map(int,input().split(" "))
Ns = input().split(" ")
N = [int (n) for n in Ns]
Ms = input().split(" ")
M = [int(n) for n in Ms]
#print(n,m,l)
#print(N,M)
i = 0
j = 0
total = 0
cnt = 0
while total < l:
  #print(i,j,total,cnt)
  if  i == n and j == m:
    break
  elif i < n and j == m:
    if total + N[i] <= l:
      total = total + N[i]
      i = i+1
      cnt = cnt + 1
    else:
      break
  elif i == n and j < m:
    if total + M[i] <= l:
      total = total + M[j]
      j = j+1
      cnt = cnt +1
    else:
      break
  elif i < n and j < m and (total+N[i] <= l or total+M[j] <= l):
    if N[i] <= M[j]:
      total = total + N[i]
      i = i+1
      cnt = cnt +1
    elif N[i] > M[j]:
      total = total + M[j]
      j = j+1
      cnt = cnt +1
  else:
    break
print(cnt)#,i,j,total,n,m,l)

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

dp=[0]*(k+1)

sa=0
cnta=0
for i in a:
  sa=sa+i
  cnta+=1
  if sa > k:
    break
  dp[sa]+=cnta

  sb=0
  cntb=0
  for j in b:
    sb=sb+j
    cntb+=1
    if sa+sb > k:
      break
    dp[sa+sb] = dp[sa] + cntb

print(max(dp))

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()))
'''
with open('./b20.txt') as f:
    N, M, K = map(int, f.readline().split())
    A = list(map(int, f.readline().split()))
    B = list(map(int, f.readline().split()))
'''

A_cnt = 0
B_cnt = 0
ans = 0
nowK = K
for A_idx in range(N):
    if nowK < A[A_idx]:
        break
    ans += 1
    nowK -= A[A_idx]
    A_cnt += 1
for B_idx in range(M):
    if nowK < B[B_idx]:
        break
    ans += 1
    nowK -= B[B_idx]
    B_cnt += 1
tmp_ans = ans
finish = False
for i in range(A_cnt, 0, -1):
    nowK += A[i]
    tmp_ans -= 1
    for j in range(B_cnt, M):
        if finish or nowK < B[j]:
            break
        nowK -= B[j]
        tmp_ans += 1
        if j == M - 1:
            finish = True
    B_idx = j
    ans = max(tmp_ans, ans)
print(ans)

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:
import sys
from io import StringIO
import unittest
import os
import bisect
import numpy

Submission status: Runtime Error

Solution code:
temp = [int(i) for i in input().split(" ")]
k = temp[2]

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

# a = [60, 90, 120]
# b = [80, 150, 80, 150]
# k = 240

gmax = 0

def create_left(aindex, bindex, time):

    global gmax

    if bindex >= len(b):
        gmax = (aindex +  bindex) if gmax < (aindex  + bindex) else gmax
        return None
    
    accm = time + b[bindex]
    if accm > k:
        gmax = (aindex +  bindex) if gmax < (aindex  + bindex) else gmax
        return None

    return {
        "value": b[bindex],
        "left": create_left(aindex, bindex + 1, accm),
        "right": create_right(aindex, bindex + 1, accm),
    }


def create_right(aindex, bindex, time):


    global gmax
    if aindex >= len(a):
        gmax = (aindex +  bindex) if gmax < (aindex  + bindex) else gmax
        
        return None
    
    accm = time + a[aindex]
    if accm > k:
        gmax = (aindex +  bindex) if gmax < (aindex  + bindex) else gmax
        
        return None

    return {
        "value": a[aindex],
        "left": create_left(aindex + 1, bindex, accm),
        "right": create_right(aindex + 1, bindex, accm),
    }



aindex = 0
bindex = 0

time = 0

bin = {
    "right": create_right(aindex, bindex, time),
    "left": create_left(aindex, bindex, time)
}
print(gmax)

Submission status: Runtime Error

Solution code:
a, b = iter(A), iter(B)
now_a, now_b = next(a), next(b)
ans, cnt_time = 1, 0
ex_a = True
ex_b = True
while cnt_time < K:
    #print(ans)
    if now_a > now_b and ex_b:
        try:
            ans += 1
            cnt_time += now_b
            #print('b', now_b, cnt_time)
            now_b = next(b)
        except StopIteration:
            ex_b = False
            continue
    elif now_a <= now_b and ex_a:
        try:
            ans += 1
            cnt_time += now_a
            #print('a', now_a, cnt_time)
            now_a = next(a)
        except StopIteration:
            ex_a = False
            continue
    elif ex_b:
        try:
            ans += 1
            cnt_time += now_b
            #print('b2', now_b, cnt_time)
            now_b = next(b)
        except StopIteration:
            ex_b = False
            continue
    elif ex_a:
        try:
            ans += 1
            cnt_time += now_a
            #print('a2', now_a, cnt_time)
            now_a = next(a)
        except StopIteration:
            ex_a = False
            continue

print(ans-1)

Submission status: Runtime Error

Solution code:
a, b = iter(A), iter(B)
now_a, now_b = next(a), next(b)
ans, cnt_time = 1, 0
ex_a = True
ex_b = True
while cnt_time < K:
    print(ans)
    if now_a > now_b and ex_b:
        try:
            ans += 1
            cnt_time += now_b
            print('b', now_b, cnt_time)
            now_b = next(b)
        except StopIteration:
            ex_b = False
            continue
    elif now_a <= now_b and ex_a:
        try:
            ans += 1
            cnt_time += now_a
            print('a', now_a, cnt_time)
            now_a = next(a)
        except StopIteration:
            ex_a = False
            continue
    elif ex_b:
        try:
            ans += 1
            cnt_time += now_b
            print('b2', now_b, cnt_time)
            now_b = next(b)
        except StopIteration:
            ex_b = False
            continue
    elif ex_a:
        try:
            ans += 1
            cnt_time += now_a
            print('a2', now_a, cnt_time)
            now_a = next(a)
        except StopIteration:
            ex_a = False
            continue

print(ans-1)

Submission status: Runtime Error

Solution code:
n,m,k = list(map(int,input().split()))
a = int(input().split())
b = int(input().split())
c = []
count = 0
maxcount = 0
for i in range(n):
  for j in range(m):
    if a[i] < b[j]:
      c[count] = a[i]
      count = count + 1
      break;
    elif a[i] == b[j]:
      c[count] = a[i]
      count = count + 1
      c[count] = b[j]
      count = count + 1
      break;
    else:
      c[count] = b[j]
      count = count + 1
      break;
      
for i in range(count):
  if k-c[i] >= 0:
    k = k-c[i]
    maxcount = maxcount + 1

print(maxcount)

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 = [0]
b = [0]
for i in range(N):
  a.appned(a[i]+A[i])
for i in range(M):
  b.append(b[i]+B[i])

ans, j = 0, M
for i in range(len(A)):
  if a[i] > K:
    break
  while B[j] > K - a[i]:
    j -= 1
  ans = max(ans, i+j)
print(ans)

Submission status: Runtime Error

Solution code:
import itertools
def main():
    n,m,k=map(int, input().split())
    a=[int(i) for i in input().split()]
    b=[int(i) for i in input().split()]

    ia = n-1
    res = n
    ib = 0
    time = sum(a)

    while(ia>=0 and ib<m):

      if(time > k):
            time -= (a[ia])
            res-=1
            ia-=1
        elif(time+b[ib]<=k):
            time += (b[ib])
            res+=1
            ib+=1
        else:
            break

    print(res)

if __name__ == '__main__':
    main()

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

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

ans = 0

while n > 0 and m > 0 and k > 0:
    if a[0] == b[0]:
        i = 0
        while i + 1 < m and i + 1 < n and a[i + 1] != b[i + 1]:
            i += 1
        if a[i] >= b[i]:
            k -= b[0]
            if k >= 0:
                ans += 1
            b.popleft()
            n -= 1
        else:
            k -= a[0]
            if k >= 0:
                ans += 1
            a.popleft()
            m -= 1
    elif a[0] > b[0]:
        k -= b[0]
        if k >= 0:
            ans += 1
        b.popleft()
        m -= 1
    else:
        k -= a[0]
        if k >= 0:
            ans += 1
        a.popleft()
        n -= 1

if n <= 0:
    while k > 0 and m > 0:
        k -= b[0]
        if k >= 0:
            ans += 1
        b.popleft()
elif m <= 0:
    while k > 0 and n > 0:
        k -= a[0]
        if k >= 0:
            ans += 1
        a.popleft()

print(ans)

Submission status: Runtime Error

Solution code:
#C
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A = [0]
B = [0]
#読書時間A,B
for i in range(n):
    A.append(A[i] + a[i])
for i in range(m):
    B.append(B[i] + b[i])
ans, j = 0, m
#Aを増やしたときA+Bがkより小さくなるようなi,jを決めて最大値を決めてる
for i in range(n + 1):
    if a[i] > k:
        break
    while b[j] > k - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)

Submission status: Runtime Error

Solution code:
def resolve():
    lines = sys.stdin.readlines()

    n, m, k = tuple(map(int, lines[0].strip().split(' ')))
    A = list(map(int, lines[1].strip().split(' ')))
    B = list(map(int, lines[2].strip().split(' ')))

    a = [0]
    b = [0]

    for i in range(n):
        a.append(a[i] + A[i])
    for i in range(m):
        b.append(b[i] + B[i])

    res = 0
    j = m
    for i in range(n+1):
        if a[i] > k:
            break
        while a[i] + b[j] > k:
            j -= 1
        res = max(res, i+j)
    print(res)

resolve()

Submission status: Runtime Error

Solution code:
package main
import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main(){
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush()
	N, M, K := nextInt(), nextInt(), nextInt()
	A := append([]int{0}, nextInts(N)...)
	B := append([]int{0}, nextInts(M)...)
	for i:=1; i<=N; i++{
		A[i] += A[i-1]
	}
	for i:=1; i<=M; i++{
		B[i] += B[i-1]
	}
	ans := 0
	for i:=0; i<=N; i++{
		rest := K-A[i]
		if rest < 0{
			break
		}
		// golangでupper_boundどうやるんだ？？？？？？・
		/// bidx := max(0, sort.Search(len(B), func(j int)bool{return rest<=B[j]}))
		// bidx := sort.Search(len(B), func(j int)bool{return rest<=B[j]})-1
		// bidx := sort.SearchInts(B, rest)
		// わからんので仕方なく手書き
		left, right := -1, len(B)
		for right - left > 1{
			mid := (left+right)/2
			if rest-B[mid]>=0{
				left = mid
			}else{
				right = mid
			}
		}
		bidx := left
		ans = max(ans, i+bidx)
	}
	fmt.Fprintln(out, ans)
}

func min(a, b int) int {
	if a<b{
		return a
	}
	return b
}

func max(a, b int) int {
	if a<b{
		return b
	}
	return a
}
func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextInts(n int) []int{
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func chars(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

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=[0]
b=[0]
for i in range(N):
	a.append(a[i] + A[i])
for i in range(M):
	b.append(b[i] + B[i])
ans, j = 0, M
for i in range(N + 1):
	if a[i] > K:
		break
	while b[j] > K - a[i]:
		j -= 1
	ans = max(ans, i + j)
print(ans)

Submission status: Runtime Error

Solution code:
from itertools import accumulate

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

A = [0] + A
A = list(accumulate(A))

B = [0] + B
B = list(accumulate(B))

ans = 0
b_cnt = m
for a_cnt in range(n+1):
    if a_cnt > k: continue

    while A[a_cnt]+B[b_cnt] > k:
        b_cnt -= 1
    ans = max(ans, a_cnt+b_cnt)

print(ans)

Submission status: Runtime Error

Solution code:
def main():
    n, m, k = [int(e) for e in input().split()]
    A = [int(e) for e in input().split()]
    B = [int(e) for e in input().split()]

    t = 0
    ca, cb = 0, 0
    for a in A:
        t += a
        if t > k:
            t -= a
            break

        ca += 1

    while True:
        t += B[cb]
        cb += 1

        if t > k:
            cb -= 1
            t -= B[cb]
            break

        if cb == len(B):
            break

    AA = [ca + cb]
    while True:
        if ca == 0 or cb == len(B):
            break

        ca -= 1
        t -= A[ca]
        while True:
            t += B[cb]
            if t > k or cb == len(B):
                break

            cb += 1

        AA.append(ca + cb)

    print(max(AA))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import numpy as np

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A_cumsum = np.array(A).cumsum()
B_cumsum = np.array(B).cumsum()
max_count_A = 0
max_count_B = 0
max_count_AB = 0
max_j = 0

for i in range(N):
  if A_cumsum[i] <= K and max_count_A <= i+1:
    max_count_A = i + 1
  else:
    break
for i in range(M):
  if B_cumsum[i] <= K and max_count_B <= i+1:
    max_count_B = i + 1
  else:
    break
    
for i in range(N):
  if A_cumsum[i] + B_cumsum[max_j] > K:
    for j in range(max_j)[::-1]:
      if A_cumsum[i] + B_cumsum[j] <= K:
        if max_count_AB <= i + j + 2:
          max_count_AB = i + j + 2
          max_j = j
        else:
        break
  else:
    for j in range(max_j, M):
      if A_cumsum[i] + B_cumsum[j] <= K and max_count_AB <= i + j + 2:
        max_count_AB = i + j + 2
        max_j = j
      else:
        break
    
print(max(max_count_A, max_count_B, max_count_AB))

Submission status: Runtime Error

Solution code:
###############################################################################
#Imports
import collections
import sys
import itertools
from functools import lru_cache
import sys
import math
from decimal import Decimal
###############################################################################
#Constants
MOD = int(1e9)+7
###############################################################################
#Helper
sys.setrecursionlimit(10**9) 
def helper():
	pass
###############################################################################
#Solver
def solve():
	n,m,k = map(int,input().split(' '))
	a = list(map(int,input().split(' ')))
	b = list(map(int,input().split(' ')))
	
	@lru_cache(None)
	def dfs(left,i1,i2):
		if (i1>=n and i2>=m) or k<=0:
			return 0
		else:
			op1,op2 = 0,0
			if i1<n and left>=a[i1]:
				op1 = 1+dfs(left-a[i1],i1+1,i2)
			if i2<m and left>=b[i2]:
				op2 = 1+dfs(left-b[i2],i1,i2+1)
			return max(op1,op2)

	print(dfs(k,0,0))
###############################################################################
#Driver
t = 1
for _ in range(t):
	solve()
###############################################################################

Submission status: Runtime Error

Solution code:
###############################################################################
#Imports
import collections
import itertools
from functools import lru_cache
import sys
import math
from decimal import Decimal
###############################################################################
#Constants
MOD = int(1e9)+7
###############################################################################
#Helper
def helper():
	pass
###############################################################################
#Solver
def solve():
	n,m,k = map(int,input().split(' '))
	a = list(map(int,input().split(' ')))
	b = list(map(int,input().split(' ')))
	
	def dfs(left,i1,i2):
		if (i1>=n and i2>=m) or k<=0:
			return 0
		else:
			op1,op2 = 0,0
			if i1<n and left>=a[i1]:
				op1 = 1+dfs(left-a[i1],i1+1,i2)
			if i2<m and left>=b[i2]:
				op2 = 1+dfs(left-b[i2],i1,i2+1)
			return max(op1,op2)

	print(dfs(k,0,0))
###############################################################################
#Driver
t = 1
for _ in range(t):
	solve()
###############################################################################

Submission status: Runtime Error

Solution code:
import sys

input = lambda: sys.stdin.readline().rstrip()

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

cnt = 0
if A[0] < B[0] and A[0] <= k:
    cnt += 1
    k -= A[0]

idx_a = 1
idx_b = 0

while k > 0:
    if B[idx_b] > A[idx_a]:
        k -= A[idx_a]
        if k >= 0: cnt += 1
        if idx_a < n - 1: idx_a += 1

    if B[idx_b] < A[idx_a]:
        k -= B[idx_b]
        if k >= 0: cnt += 1
        if idx_b < m - 1: idx_b += 1

    if B[idx_b] == A[idx_a]:
        k -= A[idx_a]
        if k >= 0: cnt += 1
        if idx_a < n - 1: idx_a += 1
        
        k -= B[idx_b]
        if k >= 0: cnt += 1
        if idx_b < m - 1: idx_b += 1

print(cnt)

Submission status: Runtime Error

Solution code:
n,m,k=map(int,input().split())
l1=list(map(int,input().split()))
l2=list(map(int,input().split()))
x=n+m
sum=0
count=0
for i in range(1,x+1):

  if i%2!=0:
    if len(l1)<1:
      sum+=l2.pop(0)
      count+=1
    else:
      sum+=l1.pop(0)
      if sum==k:
        count+=1
        break  

      if sum>k:
        break 
      count+=1

  if i%2==0:
    sum+=l2.pop(0)
    if sum==k:
      count+=1
      break        
    if sum>=k:
      break    
    count+=1
print(count)

Submission status: Runtime Error

Solution code:
import numpy as np

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
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 <= i+1:
    max_count = i + 1
  else:
    break
for i in range(N):
  if A_cumsum[i] <= K and max_count <= i+1:
    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 <= i + j + 2:
        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 <= max_count <= i + j + 2:
        max_count = i + j + 2
        max_j=j
      else:
        break
    
print(max_count)

Submission status: Runtime Error

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

sumA=sum(arr)
bpointer=0
ans=0
sumB=0
for i in range(len(arr),-1,-1):
    if i<n:
        sumA-=arr[i]
    if sumA<=k:
        while bpointer<m and sumA+sumB+brr[bpointer]<=k:
            sumB+=brr[bpointer]
            bpointer+=1
    	ans=max(ans,i+bpointer)
print(ans)

Submission status: Runtime Error

Solution code:
N, M, K =  [int(x) for x in input().split()]

stackA = [int(x) for x in input().split()]
stackB = [int(x) for x in input().split()]

indexB = 0
indexA = 0

books = 0
mostBooks = 0
time = 0

for x in stackB:
    if time + x > K:
        indexB -= 1
        break

    else:
        time += x
        indexB += 1
        books += 1

mostBooks = books

for x in stackA:
    time += x
    books += 1

    while time > K and indexB >= 0:
        time -= stackB[indexB]
        indexB -= 1
        books -= 1

    if indexB < 0 and time > K:
        break

    mostBooks = max(mostBooks, books)

print(mostBooks)

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]*(N+1)
d = [0]*(N+1)
a_sum = 0
a_num = 0
i = 0
while a_sum + a[i] <= K:
	a_sum += a[i]
	i += 1
	if i >= N:
		break
c[i] = a_sum
a_num = i

for i in range(a_num+1):
	#print(a_sum)
	d[a_num-i] = a_num-i
	#print(c)
	j = 0
	c[a_num-i] = a_sum
	while c[a_num-i] +b[j] <=K:
		c[a_num-i] += b[j]
		j += 1
		if j >= M:
			break
		
	#print(c)
	d[a_num-i] += j
	if j == M:
		break
	if c[a_num-i]-a[a_num - i-1] +b[j+1] > K :
		break
	a_sum -= a[a_num - i-1]
	

print(max(d))

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]*(N+1)
d = [0]*(N+1)
a_sum = 0
a_num = 0
i = 0
while a_sum + a[i] <= K:
	a_sum += a[i]
	i += 1
	if i >= N:
		break
c[i] = a_sum
a_num = i

for i in range(a_num+1):
	#print(a_sum)
	d[a_num-i] = a_num-i
	#print(c)
	j = 0
	c[a_num-i] = a_sum
	while c[a_num-i] +b[j] <=K:
		c[a_num-i] += b[j]
		j += 1
		if j >= M:
			break
		
	#print(c)
	d[a_num-i] += j
	if j == M:
		break
	if a[a_num - i-1] < b[j+1]:
		break
	a_sum -= a[a_num - i-1]
	

print(max(d))