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

suma = [0] * n
sumb = [0] * m
suma[0] = a[0]
sumb[0] = b[0]

for i in range(1,n):
    suma[i] = suma[i-1]+a[i]
for j in range(1,m):
    sumb[j] = suma[j-1]+b[j]

    
ans, cur= 0, m-1
for i in range(n):
    target = k - suma[i]
    if target <= 0:
        break
    for j in range(cur,-1,-1):
        if sumb[j] <= target:
            ans = max(ans, i+j+2)
            cur = 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()))

suma = [0] * n
sumb = [0] * m
suma[0] = a[0]
sumb[0] = b[0]

for i in range(1,n):
    suma[i] = suma[i-1]+a[i]
for j in range(1,m):
    sumb[j] = suma[j-1]+b[j]

ans, cur= 0, m-1
for i in range(n):
    target = k - suma[i]
    for j in range(cur,-1,-1):
        if sumb[j] <= target:
            ans = max(ans, i+j+2)
            cur = 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(' ')))

a.insert(0, 0)
b.insert(0, 0)

for i in range(1, len(a)):
  a[i] = a[i-1] + a[i]
  
for j in range(1, len(b)):
  b[i] = b[i-1] + b[i]
  

answer_list = [0]
for i in range(len(a)):
  for j in range(len(b)):
    if a[i] + b[j] < k:
      answer_list.append(i + j)
      
print(max(answer_list))

Submission status: Runtime Error

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))+[k+1]
b=list(map(int,input().split()))+[k+1]
ans=0
i=0
j=0
while k>=a[i] or k>=b[j]:
    if a[i]<b[j]:
        k-=a[i]
        i+=1
    elif b[j]<a[i]:
        k-=b[j]
        j+=1
    else:
        it=i+1
        jt=j+1
        while a[it]==b[jt]:
            it+=1
            jt+=1
        if a[it]<b[jt]:
            k -= a[i]
            i += 1
        else:
            k -= b[j]
            j += 1
    ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
"""
    Satwik_Tiwari ;) .
    4th july , 2020  - Saturday
"""

#===============================================================================================
#importing some useful libraries.
from __future__ import division, print_function

from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase


import bisect
from heapq import *
from math import *
from collections import deque
from collections import Counter as counter  # Counter(list)  return a dict with {key: count}
from itertools import combinations as comb # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl
#If the element is already present in the list,
# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect
#If the element is already present in the list,
# the right most position where element has to be inserted is returned

#==============================================================================================

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

# inp = lambda: sys.stdin.readline().rstrip("\r\n")

#===============================================================================================
#some shortcuts

mod = 1000000007
def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input
def out(var): sys.stdout.write(str(var))  #for fast output, always take string
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())
# def graph(vertex): return [[] for i in range(0,vertex+1)]
def zerolist(n): return [0]*n
def nextline(): out("\n")  #as stdout.write always print sring.
def testcase(t):
    for p in range(t):
        solve()
def printlist(a) :
    for p in range(0,len(a)):
        out(str(a[p]) + ' ')
def lcm(a,b): return (a*b)//gcd(a,b)
def power(a,b):
    ans = 1
    while(b>0):
        if(b%2==1):
            ans*=a
        a*=a
        b//=2
    return ans
def ncr(n,r): return factorial(n)//(factorial(r)*factorial(max(n-r,1)))
def isPrime(n) : # Check Prime Number or not
    if (n <= 1) : return False
    if (n <= 3) : return True
    if (n % 2 == 0 or n % 3 == 0) : return False
    i = 5
    while(i * i <= n) :
        if (n % i == 0 or n % (i + 2) == 0) :
            return False
        i = i + 6
    return True

#===============================================================================================
# code here ;))
def bs(a,l,h,x):
    while(l<h):
        # print(l,h)
        mid = (l+h)//2
        if(a[mid] == x):
            return mid
        if(a[mid] < x):
            l = mid+1
        else:
            h = mid
    return l

def sieve(a): #O(n loglogn) nearly linear
    #all odd mark 1
    for i in range(3,((10**6)+1),2):
        a[i] = 1
    #marking multiples of i form i*i 0. they are nt prime
    for i in range(3,((10**6)+1),2):
        for j in range(i*i,((10**6)+1),i):
            a[j] = 0
    a[2] = 1 #special left case
    return (a)


def bfs(g,st):
    visited = [-1]*(len(g))
    visited[st] = 0
    queue = []
    queue.append(st)
    new = []
    while(len(queue) != 0):
        s = queue.pop()
        new.append(s)
        for i in g[s]:
            if(visited[i] == -1):
                visited[i] = visited[s]+1
                queue.append(i)
    return visited


def dfsusingstack(v,st):
    d = deque([])
    visited = [0]*(len(v))
    d.append(st)
    new = []
    visited[st] = 1
    while(len(d) != 0):
        curr = d.pop()
        new.append(curr)
        for i in v[curr]:
            if(visited[i] == 0):
                visited[i] = 1
                d.append(i)
    return new

# 6
# 1 -1 2 3 -5 0
def solve():
    n,m,k = sep()
    a = lis()
    b = lis()
    # a = sorted(a)
    # b = sorted(b)

    i = 0
    j = 0
    cnt = 0
    while(i<n or j<m):
        if(i<n and j<n):
            if(k<a[i] and k<b[j]):
                break
            if(a[i]<b[j]):
                cnt+=1
                k-=a[i]
                i+=1
            else:
                cnt+=1
                k-=b[j]
                j+=1
            continue
        if(i>=n):
            if(k<b[j]):
                break
            cnt+=1
            k-=b[j]
            j+=1
            continue
        if(k<a[i]):
            break
        cnt+=1
        k-=a[i]
        i+=1

    # print(k)
    print(cnt)


testcase(1)
# testcase(int(inp()))

Submission status: Runtime Error

Solution code:
import sys 
import numpy as np

def binarySearch_canread(data, target):
    if len(data) == 0:
        return None
    if len(data) == 1:
        return data[0]

    # 追加　全部読める場合と何も読めない場合
    if target > max(data):
        return len(data)
    elif target < min(data):
        return 0

    min_diff = float('inf')
    imin = 0
    imax = len(data) - 1
    closest_num = None

    while imin <= imax:
        imid = imin + (imax - imin) // 2

        if imid + 1 < len(data):
            min_diff_right = abs(data[imid + 1] - target)
        if imid > 0:
            min_diff_left = abs(data[imid - 1] - target)

        if min_diff_left < min_diff:
            min_diff = min_diff_left 
            closest_num = data[imid - 1]
        if min_diff_right < min_diff:
            min_diff = min_diff_right
            closest_num = data[imid + 1]

        if data[imid] < target:
            imin = imid + 1
        elif data[imid] > target:
            imax = imid - 1
        else:
            return list(data).index(data[imid]) + 1 # data[imid]

    # 何冊読めるかを返したい
    differ = target - closest_num
    can_read = None
    if differ > 0: # 読める時間（target）の方が大きい
        can_read = max([i for i, x in enumerate(data) if x == closest_num]) + 1
    elif differ < 0: # 読める時間の方が少ない
        can_read = min([i for i, x in enumerate(data) if x == closest_num])



    return can_read

if __name__ == '__main__':
    read = sys.stdin.buffer.read 
    readline = sys.stdin.buffer.readline
    readlines = sys.stdin.buffer.readlines 

    N, M, K = map(int, readline().split())
    A = np.array(readline().split(), np.int64)
    B = np.array(readline().split(), np.int64)

    Acum = np.zeros(N+1, np.int64)
    Acum[1:] = np.cumsum(A)
    Bcum = np.zeros(M+1, np.int64)
    Bcum[1:] = np.cumsum(B)

    # Aから1冊ずつ取っていく
    max_read = 0
    # O(N * logN)
    for i, cumNum in enumerate(Acum): # Aを1つも撮らない場合もあるので0から
        if cumNum <= K:
            limit = K - cumNum
            # O(logN)
            can_reading = i + binarySearch_canread(Bcum[1:], limit)
            if (max_read < can_reading):
                max_read = can_reading

    print(max_read)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
from collections import deque


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


def LI(): return list(map(int, sys.stdin.readline().split()))


def main():
    n, m, k = MI()
    a = deque(LI())
    b = deque(LI())

    A = [0 for i in range(len(a))]
    B = [0 for i in range(len(b))]
    A[0] = a[0]
    B[0] = b[0]

    for i in range(1, len(a)):
        A[i] = A[i-1]+a[i]
    for i in range(1, len(b)):
        B[i] = B[i-1]+b[i]

    index = m-1
    ans = [0]
    for i in range(len(a)):
        rest = k - A[i]
        if rest < 0:
            break

        while B[index] > rest:
            index -= 1
            if index == 0:
                break
        ans.append(i + index+2)

    print(max(ans))

    # oj t -c "pypy3 main.py"
    # acc s main.py -- --guess-python-interpreter pypy
main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
from collections import deque


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


def LI(): return list(map(int, sys.stdin.readline().split()))


def main():
    n, m, k = MI()
    a = deque(LI())
    b = deque(LI())

    read = []
    isAll = False

    while sum(read) <= k:
        if len(a) == 0 and len(b) == 0:
            isAll = True
            break
        if len(a) == 0 or a[0] >= b[0]:
            b_top = b.popleft()
            read.append(b_top)
            continue
        if len(b) == 0 or a[0] < b[0]:
            a_top = a.popleft()
            read.append(a_top)
            continue

    if isAll:
        print(len(read))
    else:
        print(len(read) - 1)


# oj t -c "pypy3 main.py"
# acc s main.py -- --guess-python-interpreter pypy
main()

Submission status: Runtime Error

Solution code:
# from math import factorial,sqrt,ceil #,gcd
# from itertools import permutations,combinations,combinations_with_replacement
# from collections import deque,Counter
# from bisect import bisect_left
# from heapq import heappush,heappop
# from numba import njit
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from fractions import gcd

# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

import numpy as np    # numpy.lcm()
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb,perm #permはnPk
# import networkx as nx
# G = Graph()

# slist = "abcdefghijklmnopqrstuvwxyz"
MOD = 10**9 + 7
N,M,K = map(int,input().split())
# lisA = list(map(int,input().split()))
arrA = np.array([0] + list(map(int,input().split())))
arrB = np.array([0] + list(map(int,input().split())))

arrA = np.cumsum(arrA,dtype="int64")
arrB = np.cumsum(arrB,dtype="int64")

memo = np.add.outer(arrA,arrB) <= K
j = M
ans = 0
for i in range(N+1):
    while j >= 0:
        if memo[i][j]:
            ans = max(i+j,ans)
            break
        j -= 1

print(ans)
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

Submission status: Runtime Error

Solution code:
# from math import factorial,sqrt,ceil #,gcd
# from itertools import permutations,combinations,combinations_with_replacement
# from collections import deque,Counter
# from bisect import bisect_left
# from heapq import heappush,heappop
# from numba import njit
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from fractions import gcd

# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

import numpy as np    # numpy.lcm()
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb,perm #permはnPk
# import networkx as nx
# G = Graph()

# slist = "abcdefghijklmnopqrstuvwxyz"
MOD = 10**9 + 7
N,M,K = map(int,input().split())
# lisA = list(map(int,input().split()))
arrA = np.array([0] + list(map(int,input().split())))
arrB = np.array([0] + list(map(int,input().split())))

arrA = np.cumsum(arrA,dtype="int64")
arrB = np.cumsum(arrB,dtype="int64")
print(arrA)
print(arrB)

memo = np.add.outer(arrA,arrB) <= K
print(memo)
j = M
ans = 0
for i in range(N+1):
    while j >= 0:
        if memo[i][j]:
            ans = max(i+j,ans)
            break
        j -= 1

print(ans)
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

Submission status: Runtime Error

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

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

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

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

a_temp = a[0]
b_temp = b[0]
temp = 0
count = 0
hour = 0
i = 0
j = 0

while k > hour:
    
    count += 1
    if a_temp <= b_temp:
        hour += a_temp
        i += 1
        if i == len(a):
            a_temp = 10**10
        else:
            a_temp = a[i]
    else:
        hour += b_temp
        j += 1
        if j == len(b):
            b_temp = 10**10
        else:
            b_temp = b[i]

print(count)

Submission status: Runtime Error

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

i_l, j_l = [0], [0]

best0 = M
ans = 0

for i in range(N):
    i_l.append(i_l[i] + a_l[i])

for i in range(M):
    j_l.append(j_l[i] + b_l[i])

# for j in range(M):
#     total += b_l[j]
#     if total > K:
#         best0 = j-1
#         break
#     elif total == K:
#         best0 = j
#     else:
#         continue

for k in range(N+1):
    if i_l[i] > K:
        break
    while i_l[k] + j_l[best0] > K:
        best0 -= 1
    ans = max(ans, k+best0)
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
time = 0
while time < K:
    if not A:
        ans += 1
        if time + B[0] > K:
            break
        time += B[0]
        B.pop(0)
    elif not B:
        ans += 1
        if time + A[0]> K:
            break
        time += A[0]
        A.pop(0)
    elif A[0] > K or B[0] > K:
        break
    elif A[0] == B[0]:
        if A[1] > B[1]:
            if time + B[0] > K:
                break
            time += B[0]
            ans += 1
            B.pop(0)
        elif A[1] < B[1]:
            if time + A[0] > K:
                break
            time += B[0]
            ans += 1
            A.pop(0)
    elif A[0] > B[0] :
        if time + B[0] > K:
            break
        time += B[0]
        ans += 1
        B.pop(0)
    elif A[0] < B[0]:
        if time + A[0] > K:
            break
        time += B[0]
        ans += 1
        A.pop(0)
print(ans)

Submission status: Runtime Error

Solution code:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
time = 0
while time < K:
    if not A:
        ans += 1
        if time + B[0]:
            break
        time += B[0]
        B.pop(0)
    elif not B:
        ans += 1
        if time + A[0]:
            break
        time += A[0]
        A.pop(0)
    elif A[0] > K or B[0] > K:
        break
    elif A[0] == B[0]:
        if A[1] > B[1]:
            if time + B[0]:
                break
            time += B[0]
            ans += 1
            B.pop(0)
        elif A[1] < B[1]:
            if time + A[0]:
                break
            time += B[0]
            ans += 1
            A.pop(0)
    elif A[0] > B[0] :
        if time + B[0]:
            break
        time += B[0]
        ans += 1
        B.pop(0)
    elif A[0] < B[0]:
        if time + A[0]:
            break
        time += B[0]
        ans += 1
        A.pop(0)
print(ans)

Submission status: Runtime Error

Solution code:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
time = 0
while time < K:
    if not A:
        ans += 1
        time += B[0]
        B.pop(0)
    elif not B:
        ans += 1
        time += A[0]
        A.pop(0)
    elif A[0] > K or B[0]> K:
        break
    elif A[0] == B[0]:
        if A[1] > B[1]:
            time += B[0]
            ans += 1
            B.pop(0)
        elif A[1] < B[1]:
            time += B[0]
            ans += 1
            A.pop(0)
    elif A[0] > B[0] :
        time += B[0]
        ans += 1
        B.pop(0)
    elif A[0] < B[0]:
        time += B[0]
        ans += 1
        A.pop(0)
print(ans)

Submission status: Runtime Error

Solution code:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
time = 0
while time < K:
    if not A:
        ans += 1
        time += B[0]
        B.pop(0)
    elif not B:
        ans += 1
        time += A[0]
        A.pop(0)
    elif A[0] == B[0]:
        if A[1] > B[1]:
            time += B[0]
            ans += 1
            B.pop(0)
        elif A[1] < B[1]:
            time += B[0]
            ans += 1
            A.pop(0)
    elif A[0] > B[0] :
        time += B[0]
        ans += 1
        B.pop(0)
    elif A[0] < B[0]:
        time += B[0]
        ans += 1
        A.pop(0)
print(ans)

Submission status: Runtime Error

Solution code:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
time = 0
while time < K:
    if not A:
        ans += 1
        time += B[0]
        B.pop(0)
    elif not B:
        ans += 1
        time += A[0]
        A.pop(0)
    elif A[0] == B[0]:
        if A[1] > B[1]:
            time += B[0]
            ans += 1
            B.pop(0)
        else A[1] < B[1]:
            time += B[0]
            ans += 1
            A.pop(0)
    elif A[0] > B[0] :
        time += B[0]
        ans += 1
        B.pop(0)
    elif A[0] < B[0]:
        time += B[0]
        ans += 1
        A.pop(0)
print(ans)

Submission status: Runtime Error

Solution code:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
time = 0
while time < K:
    if not A:
        ans += 1
        time += B[0]
        B.pop(0)
    elif not B:
        ans += 1
        time += A[0]
        A.pop(0)
    elif A[0] = B[0]:
        if A[1] > B[1]:
            time += B[0]
            ans += 1
            B.pop(0)
        else A[1] < B[1]:
            time += B[0]
            ans += 1
            A.pop(0)
    elif A[0] > B[0] :
        time += B[0]
        ans += 1
        B.pop(0)
    elif A[0] < B[0]:
        time += B[0]
        ans += 1
        A.pop(0)
print(ans)

Submission status: Runtime Error

Solution code:
import sys
N,M,K=list(map(int,input().split()))
A=list(map(int,input().split()))
B=list(map(int,input().split()))
k=K
I=0
yomu=[]
for a in A:
    if k<a:
        break
    I+=1
    k-=a
    yomu.append(a)
while len(B)>0 and k>=B[0]:
    I+=1
    k-=B.pop(0)
if I==0:
    for b in B:
        if k<a:
            break
        I+=1
        k-=b
    print(I)
    sys.exit()
maxI=I
while yomu:
    k+=yomu.pop(-1)
    I=len(yomu)
    while True:
        if B==[]:
            break
        if k<B[0]:
            break
        k-=B.pop(1)
        I+=1
    maxI=max([I,maxI])
print(maxI)

Submission status: Runtime Error

Solution code:
import sys
n, m, k = map(int, sys.stdin.readline().rstrip().split(' '))

a = map(int, sys.stdin.readline().rstrip().split(' '))
b = map(int, sys.stdin.readline().rstrip().split(' '))

c = 0
total = 0
while total <= k:
	if len(a) > 0 and len(b) > 0:
      if a[0] < b[0]:
        x = a[0]
        a.pop(0)
      else:
        x = b[0]
        b.pop(0)
    elif len(a) > 0:
      x = a[0]
      a.pop(0)
    elif len(b) > 0:
      x = b[0]
      b.pop(0)
    else:
      break
    total += x
    if total > k:
      break
    else:
      c += 1

print(c)

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

ruiA = [0]
ruiB = [0]
for i in range(N):
    ruiA.append(ruiA[-1] + A[i])
for i in range(M):
    ruiB.append(ruiB[-1] + B[i])

MAX = 0
i = 0
for j in range(M, -1, -1):
    if ruiA[i] + ruiB[j] <= K:
        MAX = max(MAX, i+j)
        best = j
    break
    
for i in range(1, N+1):
    for j in range(best, -1, -1):
        if ruiA[i] + ruiB[j] <= K:
            MAX = max(MAX, i+j)
        break


print(MAX)

Submission status: Runtime Error

Solution code:
from functools import lru_cache

N, M, K = (int(i) for i in input().split())
a = list(reversed([int(i) for i in input().split()]))
b = list(reversed([int(i) for i in input().split()]))

@lru_cache(None)
def nbooks(budget, i, j):
    # the number of books you can read with budget
    # and book stacks a[:i+1] and b[:j+1]
    ab = -1 if i < 0 else budget - a[i]
    bb = -1 if j < 0 else budget - b[j]

    if ab < 0 and bb < 0:
        return 0

    # there is budget to read at least one of the books
    return 1 + max(
            nbooks(ab, i-1, j),
            nbooks(bb, i, j-1))

max_books = nbooks(K, N-1, M-1)
print(max_books)

Submission status: Runtime Error

Solution code:
from functools import lru_cache

N, M, K = (int(i) for i in input().split())
a = list(reversed([int(i) for i in input().split()]))
b = list(reversed([int(i) for i in input().split()]))

@lru_cache(None)
def nbooks(budget, i, j):
    # the number of books you can read with budget
    # and book stacks a[:i+1] and b[:j+1]
    ab = -1 if i < 0 else budget - a[i]
    bb = -1 if j < 0 else budget - b[j]

    if ab < 0 and bb < 0:
        return 0

    # there is budget to read at least one of the books
    return 1 + max(
            nbooks(ab, i-1, j),
            nbooks(bb, i, j-1))

max_books = nbooks(K, N-1, M-1)
print(max_books)

Submission status: Runtime Error

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

    a, b = [0], [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:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [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:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0],[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+i):
        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:
n,m,k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
 
ans = 0
time = 0
 
 
for i in range(len(a)):
    time += a[i]
    if time > k:
        time -=a[i]
        break
    ans += 1
    
count_a = ans
 
for j in range(len(b)):
    time += b[j]
    if time > k:
        while count_a > 0 & time > k:
            time -= a[count_a]
            count_a -= 1
        if time > k:
            tmp = 0
        else:
            tmp = count_a + j
    if tmp > ans :
        ans = tmp
    
print(ans)

Submission status: Runtime Error

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

a_sum = [0]
for i, minute in enumerate(a):
        a_sum.append(a_sum(i)+minute)
b_sum = [0]
for i, minute in enumerate(b):
        b_sum.append(b_sum(i)+minute)

B = m
ans_list = []

for i in a_sum:
        if i > k:
                ans_list.append(i)
                continue
        for j in b_sum[::-1]:
                if j <= k-i:
                        ans_list.append(i+B)
                        break
                elif j > k-i:
                        B -= 1

print(max(ans_list))

Submission status: Runtime Error

Solution code:
import bisect

n, m, k = map(int, input().split())
a, b = [0], [0]
for i, (a_, b_) in enumerate(zip(input().split(), input().split())):
    a.append(a[i] + int(a_))
    b.append(b[i] + int(b_))

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

print(res)