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:
# -*- coding: utf-8 -*-
a = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

N = a[0]
M = a[1]
K = a[2]

count = 0 #読んだ冊数を記録
count_time = 0 #読んだ時間を記録
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:
ans=0
n, m, k=map(int, input().split())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
sum=sum(a)+sum(b)
while sum > k:
  if a[len(a)-1] > b[len(b)-1]:
    sum=sum-a.pop(len(a)-1)
  else:
    sum=sum-b.pop(len(b)-1)
  ans=ans+1
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()))

c = [0]
d = 0
for i in range(n):
    d += a[i]
    c.append(d)

e = [0]
f = 0
for i in range(m):
    f += b[i]
    e.append(f)


ans = 0
j = q-1
for i in range(n):
    if c[i] > k:
        break
    else:
        while c[i] + e[j] > k:
            j -= 1
    ans = max(i + j,ans)

print(ans)

Submission status: Runtime Error

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

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

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

c = [0]
d = 0
for i in range(n):
    d += a[i]
    c.append(d)

e = [0]
f = 0
for i in range(n):
    f += b[i]
    e.append(f)


ans = 0
j = q-1
for i in range(n):
    if c[i] > k:
        break
    else:
        while c[i] + e[j] > k:
            j -= 1
    ans = max(i + j,ans)

print(ans)

Submission status: Runtime Error

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

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

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

c = [0]
d = 0
for i in range(n):
    d += a[i]
    c.append(d)
    if d > k:
        break

e = [0]
f = 0
for i in range(n):
    f += b[i]
    e.append(f)
    if f > k:
        break

p = len(c)
q = len(e)

ans = 0
j = q-1
for i in range(p):
    if c[i] > k:
        break
    else:
        while c[i] + e[j] > k:
            j -= 1
    ans = max(i + j,ans)

print(ans)

Submission status: Runtime Error

Solution code:
in_1 = input()
in_2 = input()
in_3 = input()

import numpy as np

N, M, K = np.array(in_1.split(' ')).astype(int)
A = np.array(in_2.split(' ')).astype(int)
B = np.array(in_3.split(' ')).astype(int)

def read_book(ia, ib, desk, read_time):
    if desk == 'A':
        read_time += A[ia]

    if desk == 'B':
        read_time += B[ib]
   
    if read_time > K:
        return 0

    if read_time == K:
        return ia + ib + 2

    read_count = ia + ib + 2
    if ia + 1 < N:
        count = read_book(ia + 1, ib, 'A', read_time)
        read_count = max(read_count, count)

    if ib + 1 < M:
        count = read_book(ia, ib + 1, 'B', read_time)
        read_count = max(read_count, count)

    return read_count

read_count = read_book(-1, -1, None, 0)
print(read_count)

Submission status: Runtime Error

Solution code:
in_1 = input()
in_2 = input()
in_3 = input()

import numpy as np

N, M, K = np.array(in_1.split(' ')).astype(int)
A = np.array(in_2.split(' ')).astype(int)
B = np.array(in_3.split(' ')).astype(int)

def read_book(ia, ib):
    read_time = np.sum(A[:ia]) + np.sum(B[:ib])
    if read_time > K:
        return 0

    if read_time == K:
        return ia + ib

    read_count = ia + ib
    if ia < N:
        count = read_book(ia + 1, ib)
        read_count = max(read_count, count)

    if ib < M:
        count = read_book(ia, ib + 1)
        read_count = max(read_count, count)

    return read_count

read_count = read_book(0, 0)
print(read_count)

Submission status: Runtime Error

Solution code:
import numpy as np

in_1 = input()
in_2 = input()
in_3 = input()

N, M, K = np.array(in_1.split(' ')).astype(int)
A = np.array(in_2.split(' ')).astype(int)
B = np.array(in_3.split(' ')).astype(int)

def read_book(ia, ib):
    read_time = np.sum(A[:ia]) + np.sum(B[:ib])
    if read_time > K:
        return 0

    read_count = ia + ib
    if ia < N:
        count = read_book(ia + 1, ib)
        read_count = max(read_count, count)

    if ib < M:
        count = read_book(ia, ib + 1)
        read_count = max(read_count, count)

    return read_count

read_count = read_book(0, 0)
print(read_count)

Submission status: Runtime Error

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

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

sum = []
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])

for i in range(N):
  if a[i+1] > K:
    break
  for j in range(M):
    if a[i+1]+b[j+1] > K:
      sum.append(i+j)
      break

ans = max(sum)
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()))

sum = []
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])

for i in range(N):
  if a[i] > K:
    break
  for j in range(M):
    if a[i]+b[j] > K:
      sum.append(i+j+1)
      break

ans = max(sum)
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()))

sum = []

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

sum = []

for i in N:
  sum_temp = 0
  for j in i:
    sum_temp += A[j]
  if sum_temp > K:
    break
  for j in M:
    sum_temp += B[j]
    if sum_temp > K:
      sum.append(i+j-1)
      break
 
ans = max(sum)
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()))
 
S=[]
 
for i in N:
  sum_temp = 0
  for j in i:
    sum_temp += A[j]
    if sum_temp > K:
      break
    for l in M:
      sum_temp += B[l]
      if sum_temp > K:
        sum.append(j+l)
        break
 
ans = max(S)
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()))

S=[]

for i in N:
  sum_temp = 0
  for j in i:
    sum_temp += A[j]
    if sum_temp > K:
      break
    for j in M:
      sum_temp += B[j]
      if sum_temp > K:
        sum = sum_temp
        break
  S.append(sum)
 
ans = max(S)
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()))
Sum = []

for i in N:
  sum_temp = 0
  for j in i:
    sum_temp += A[j]
    if sum_temp > K:
      break
    for j in M:
      sum_temp += B[j]
      if sum_temp > K:
        sum = sum_temp
        break
  Sum.append(sum)

ans = max(Sum)
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()))

max=0

A.insert(0, 0)
A = numpy.cumsum(A)
B.insert(0,0)
B = numpy.cumsum(B)

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:
import math
import sys
import itertools
from math import gcd
from math import sqrt
from sys import stdin
def input() : return stdin.readline().rstrip()
def mips():
    return map(int,input().split())
def ii():
    return int(input())
sys.setrecursionlimit(10**9)

N,M,K = mips()
A = [i for i in mips()]
B = [i for i in mips()]
# N,M <= 200000
ans = 0
clock = K
A2 = [0]
B2 = [0]
for i in range(1,N+1):
    ai = A2[i-1] + A[i-1]
    A2.append(ai)
for i in range(1,M+1):
    bi = B2[i-1] + B[i-1]
    B2.append(bi)
for i in range(N+1):
    j = M
    if A2[i] > K:
        break
    while (B2[j] + A[i] > K):
        j -= 1
    ans = max(ans,i+j)
print(ans)

Submission status: Runtime Error

Solution code:
import math
import sys
import itertools
from math import gcd
from math import sqrt
from sys import stdin
def input() : return stdin.readline().rstrip()
def mips():
    return map(int,input().split())
def ii():
    return int(input())
sys.setrecursionlimit(10**9)

N,M,K = mips()
A = [i for i in mips()]
B = [i for i in mips()]
# N,M <= 200000
ans = 0
clock = K
A2 = [0]
B2 = [0]
for i in range(1,N+1):
    ai = A2[i-1] + A[i-1]
    A2.append(ai)
for i in range(1,M+1):
    bi = B2[i-1] + B[i-1]
    B2.append(bi)
for i in range(N+1):
    j = M
    if A[i] > K:
        break
    while (j >= 0):
        if A2[i] + B2[j] <= K:
            ans = max(ans,i+j)
        j -= 1
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()))

a_=[]
b_=[]
tmp = 0
for i in a:
    tmp += i
    a_.append(tmp)
tmp = 0
for i in b:
    tmp += i
    b_.append(tmp)

if a_[0]>k and b_[0]>k:
    print(0)
    sys.exit()

if a_[0]>k:
    asn=0
    for i in b_:
        asn+=1
        if i > k:
            print(asn)
            sys.exit()

if b_[0]>k:
    asn=0
    for i in a_:
        asn+=1
        if i > k:
            print(asn)
            sys.exit()

ans=0
j = m-1
for i in range(n):
    if a_[i] > k:
        continue
    while b_[j] + a_[i] > k:
        j -= 1
    ans = max(ans,i+j+2)
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()))

a_=[]
b_=[]
tmp = 0
for i in a:
    tmp += i
    a_.append(tmp)
tmp = 0
for i in b:
    tmp += i
    b_.append(tmp)

if a_[0]>k and b_[0]>k:
    print(0)
    exit()

if a_[0]>k:
    asn=0
    for i in b_:
        asn+=1
        if i > k:
            print(asn)
            exit()

if b_[0]>k:
    asn=0
    for i in a_:
        asn+=1
        if i > k:
            print(asn)
            exit()


ans=0
j = m-1
for i in range(n):
    if a_[i] > k:
        continue
    while b_[j] + a_[i] > k:
        j -= 1
    ans = max(ans,i+j+2)
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 = [0 for _ in range(N)]
b = [0 for _ in range(M)]

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

Submission status: Runtime Error

Solution code:
# /usr/bin/python3
# -*- coding: utf-8 -*-
from queue import Queue
from queue import LifoQueue as Stack
from math import sqrt, floor, ceil, log2, log10, pi
from fractions import gcd
from itertools import permutations, combinations
from operator import itemgetter
from functools import cmp_to_key


INF=1001001001
__MOD__=(10**9)+7
yn = 'YNeos'
judge = False
cnt = 0
ans = None


def lcm(a, b):
    return (a*b) // gcd(a,b)

def intinput():
    return int(input())

def mulinputs():
    return map(int,input().split())

def lineinputs(func=intinput):
    datas = []
    while True:
        try:
            datas.append(func())
        except EOFError:
            break
    return datas

class ModInt():
    def __init__(self, x):
        self.__x = (x % __MOD__)
    def __add__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x + other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x + other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __radd__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x + self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x + self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __sub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x - other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x - other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rsub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x - self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x - self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __mul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rmul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x * self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x * self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __truediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rtruediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x * self.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x * self.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __pow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(self.__x, other.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(self.__x, other.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")
    def __rpow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(other.__x, self.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(other.__x, self.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")

    def __modinv(self, m=__MOD__):
        a = self.__x
        if a == 0:
            raise ZeroDivisionError()
        if gcd(a, m) != 1:
            raise Exception("%sの逆数は求まりません。" % a)
        b, u, v = m, 1, 0
        while b != 0:
            t = a//b;
            a -= t*b
            a, b = b, a
            u -= t * v
            u, v = v, u
        u %= m
        if u < 0:
            u += m
        return u
    def __int__(self):
        return self.__x
    def __str__(self):
        return str(self.__x)



if __name__ == '__main__':
    N, M, K = mulinputs()
    an = list(map(int, input().split()))
    bm = list(map(int, input().split()))

#     # i, j, la, lb, t = 0, 0, len(an), len(bm), 0
#     # l = max(la, lb)
#     # while True:
#     #     if i < la and j < lb:
#     #         a, b = an[i], bm[j]
#     #     elif i < la:
#     #         a, b = an[i], INF
#     #     elif j < lb:
#     #         a, b = INF, bm[j]
#     #     else:
#     #         break
#     #     c = 0
#     #     if a <= b:
#     #         c = a
#     #         i += 1
#     #     else:
#     #         c = b
#     #         j += 1
#     #     if t + c <= K:
#     #         t += c
#     #         cnt += 1
#     #     else:
#     #         break
#     # # t = 0
#     # # while len(an) != 0 or len(bm) != 0:
#     # #     a, b = INF, INF
#     # #     if len(an) > 0:
#     # #         a = an.pop()
#     # #     if len(bm) > 0:
#     # #         b = bm.pop()
#     # #     if t + min(a, b) > K:
#     # #         break
#     # #     if a >= b:
#     # #         t += a
#     # #         cnt += 1
#     # #         bm.append(b)
#     # #     else:
#     # #         t += b
#     # #         cnt += 1
#     # #         an.append(a)
# # 
#     # # 出力
#     # print(cnt)
# 
# 
#     la, lb = len(an), len(bm)
#     def dfs(i, j, t, c):
#         a = INF if i >= la else an[i]
#         b = INF if j >= lb else bm[j]
#         if t + min(a,b) > K:
#             return c
#         return max(dfs(i+1, j, t+a, c+1), dfs(i, j+1, t+b, c+1), c)
# 
#     print(dfs(0,0,0,0))


    # 復習
    ans, aidx, bidx = 0, 0, 0
    while True:
        if ainx == len(an):
            break
        if ans+an[aidx] <= K:
            ans += an[aidx]
            aidx +=1
        else:
            break
    while True:
        if bidx = len(bm):
            break
        if ans + bm[bidx] <= K:
            ans += bm[bidx]
            bidx += 1
        else:
            break
    ansidx = aidx + bidx
    while aidx > 0:
        aidx -=1
        ans -= an[aidx]
        while True:
            if bidx == len(bm):
                break
            if ans + bm[bidx] <= K:
                ans += bm[bidx]
                bidx += 1
            else:
                break
        ansidx = max(ansidx, aidx+bidx)
    print(ansidx)

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

for i in range(1,n):
  a[i] += a[i-1]
for i in range(1,m):
  b[i] += b[i-1]
a_max = 0
for i in range(n, 0, -1)
  if a[i-1] <= k:
    a_max = i
    break
b_max = 0
for i in range(m, 0, -1)
  if a[i-1] <= k:
    b_max = i
    break
    
ans = 0
for i in range(a_max, 0, -1):
  p = 0
  q = 0
  if a[i-1] <= k:
    p = a[i-1]
    q = i
  for j in range(b_max, 0, -1):
    if p + b[j-1] <= k:
      ans = max(ans, q + j)
    
print(ans)

Submission status: Runtime Error

Solution code:
def main():
    N, M, K = map(int, input().split())
    A = deque([int(a) for a in input().split()])
    B = deque([int(b) for b in input().split()])
    Bsum = sum(B)
    ans = Asum = 0
    idx_b = len(B) - 1

    A.appendleft(0)

    for i in range(len(A)):
        Asum += A[i]

        for j in range(idx_b + 1):
            if Asum + Bsum > K:
                if idx_b >= 0:
                    Bsum -= B[idx_b]
                    idx_b -= 1
                else:
                    break
            else:
                break

        if Asum + Bsum <= K:
            ans = max(ans, i + (idx_b + 1))

    print(ans)
 
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
N, M, K = map(int, input().split())
arr_a = list(map(int, input().split()))
arr_b = list(map(int, input().split()))
ans_a =0
ans_b =0
time =0

for i in range(N):
    if time + arr_a[i] > K:
        break
    else:
        ans_a +=1
        time += arr_a[i]
for i in range(M):
    if time + arr_b[i] > K:
        break
    else:
        ans_b +=1
        time += arr_b[i]

ans = ans_a + ans_b
ans_koho = ans_a + ans_b
cnt_b = ans_b

for i in range(ans_a):
    ans_koho -= 1
    time -= arr_a[-1*(i+1)]

    while True:
        if cnt_b == M:
            break
        elif time + arr_b[cnt_b] > K:
            break
        else:
            time += B[cnt_b]
            cnt_b += 1
            ans_koho += 1
    ans = max(ans, ans_koho)

print(ans)

Submission status: Runtime Error

Solution code:
import copy
L = list(map(int, input().split())) # N, M, K=map(int,input().split())
N=L[0]
M=L[1]
K=L[2]
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = 0
b = 0
p=N
q=M
for i in range(N):
    a=a+A[i]
    if a>K:
        a=a-A[i]
        p=i
        break
if a<K:
    X=K-a
    for j in range(M):
        b=b+B[j]
        if b>X:
            b=b-B[j]
            q=j
            break
c=a+b
count=p+q
F=[p+q]
u=0
for i in range(p):
    u=0
    c=c-A[p-i-1]
    count=count-1
    for j in range(M-q):
        c=c+B[q+j]
        if K<c:
            c=c-B[q]
            F.append(copy.copy(count))
            u=1
            break
        else:
            count=count+1
            q=q+1
    if u==0:
        F.append(copy.copy(count))
        break
print(max(F))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-


def main():
    n, m, k = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    a = A[0]
    A2 = [a]
    b = B[0]
    B2 = [b]
    for i in range(1, n):
        a += A[i]
        A2.append(a)

    for i in range(1, m):
        b += B[i]
        B2.append(b)
    max = -2
    for ia, aa in enumerate(A2):
        for ib, bb in enumerate(B2):
            if aa + bb > k:
                break
            if ia + ib > max:

                max = ia + ib
    print(max + 2)


def answer():
    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)
if __name__ == '__main__':
    answer()

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()))
na = []
c = 0
for booka in a:
  c += booka
  na.append(c)
nb = []
d = 0
for bookb in b:
  d += bookb
  nb.append(d)
maxa = 0
for i in range(n):
  for j in range(maxa-i,m):
    if na[i] + nb[j] <= k:
      maxa = max(maxa,i+j+2)
print(maxa)

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()))
for i in range(1,N):
  A[i]+=A[i-1]
for i in range(1,M):
  B[i]+=B[i-1]

j,best=0,0
for j in range(M):
  if B[j] > K: break
  else:best=j+1
j＝0
for i in range(N):
  if A[i] > K: break
  while j < M:
    if A[i]+B[j] > K: break
    else: j+=1
  best=max(best,i+1+j)
print(best)

Submission status: Runtime Error

Solution code:
import numpy as np
import math
import collections
import bisect
from difflib import SequenceMatcher


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

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

    cumsumA = np.cumsum(A)
    p = bisect.bisect_left(cumsumA, K + 0.1)
    time = cumsumA[p - 1]
    tmp = p
    ans = tmp

    cntA = 0
    import numpy as np


import math
import collections
import bisect
from difflib import SequenceMatcher


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

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

    cumsumA = np.cumsum(A)
    a = bisect.bisect_left(cumsumA, K + 0.1)
    time = cumsumA[a - 1]
    tmp = a
    ans = tmp

    b = 0
    while(b < len(B)):
        if time + B[b] <= K:
            time += B[b]
            tmp += 1
            b += 1
            if tmp > ans:
                ans = tmp
        else:
            if a < 0:
                break
            time -= A[a]
            a += -1
            tmp += -1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

counter = 0
i = 0 # A count
j = 0 # B count
AB = [A,B]
print(AB)
while(K>0 and (K>=int(AB[0][i]) or K>=int(AB[1][j]))):
    if(i == len(A)):
        counter += 1
        K = K - int(AB[1][j])
        j += 1
    elif(j == len(B)):
        counter += 1
        K = K - int(AB[0][i])
        i += 1
    elif(int(AB[0][i])>int(AB[1][j])):
	    counter += 1
	    K = K - int(AB[0][i])
	    i += 1
    else:
        counter += 1
        K = K - int(AB[1][j])
        j += 1

print(counter)

Submission status: Runtime Error

Solution code:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
i = 0
j = 0
if K < A[0] and K < B[0]:
  print(0)
  exit(0)
if K >= sum(A) + sum(B):
  print(N + M)
  exit(0)
ans = 0
while True:
  while A[i] >= B[j]:
    K = K - B[j]
    j += 1
    if j == M:
      ans += j
      while K >= 0:
        K = K - A[i]
        i += 1
        if K == 0:
          print(ans + i)
          exit(0)
        elif K < 0:
          print(ans + i -1) 
          exit(0)
    if K == 0:
      print(ans + j)
      exit(0)
    elif K < 0:
      print(ans + j -1)
      exit(0)
  ans += j
  while A[i] <= B[j]:
    K = K - A[i]
    i += 1
    if K == 0:
      print(ans + i)
      exit(0)
    elif K < 0:
      print(ans + i -1) 
      exit(0)
  ans += i
print(ans)

Submission status: Runtime Error

Solution code:
 j
      while K >= 0:
        K = K - A[i]
        i += 1
        if K == 0:
          print(ans + i)
          exit(0)
        elif K < 0:
          print(ans + i -1) 
          exit(0)
    if K == 0:
      print(ans + j)
      exit(0)
    elif K < 0:
      print(ans + j -1)
      exit(0)
  ans += j
  while A[i] <= B[j]:
    K = K - A[i]
    i += 1
    if K == 0:
      print(ans + i)
      exit(0)
    elif K < 0:
      print(ans + i -1) 
      exit(0)
  ans += i
print(ans)

Submission status: Runtime Error

Solution code:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
i = 0
j = 0
if K < A[0] and K < B[0]:
  print(0)
  exit(0)
if K >= sum(A) + sum(B):
  print(N + M)
  exit(0)
ans = 0
while True:
  while A[i] >= B[j]:
    j += 1
    K = K - B[j]
    if K == 0:
      print(ans + j)
      exit(0)
    elif K < 0:
      print(ans + j -1)
      exit(0)
  ans += j
  while A[i] <= B[j]:
    i += 1
    K = K - A[i]
    if K == 0:
      print(ans + i)
      exit(0)
    elif K < 0:
      print(ans + i -1) 
      exit(0)
  ans += i
print(ans)

Submission status: Runtime Error

Solution code:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
i = 0
j = 0
if K < A[0] and K < B[0]:
  print(0)
  exit(0)
if K >= sum(A) + sum(B):
  print(N + M)
  exit(0)
ans = 0
while True:
  while A[i] >= B[j]:
    j += 1
  	K = K - B[j]
    if K == 0:
      print(ans + j)
      exit(0)
    elif K < 0:
      print(ans + j -1)
      exit(0)
  ans += j
  while A[i] <= B[j]:
    i += 1
  	K = K - A[i]
    if K == 0:
      print(ans + i)
      exit(0)
    elif K < 0:
      print(ans + i -1) 
      exit(0)
  ans += i
print(ans)

Submission status: Runtime Error

Solution code:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
i = 0
j = 0
if K < A[0] and K < B[0]:
  print(0)
  exit(0)
if K >= sum(A) + sum(B):
  print(N + M)
  exit(0)
ans = 0
while TRUE:
  while A[i] >= B[j]:
    j += 1
  	K = K - B[j]
    if K == 0:
      print(ans + j)
      exit(0)
    elif K < 0:
      print(ans + j -1)
      exit(0)
  ans += j
  while A[i] <= B[j]:
    i += 1
  	K = K - A[i]
    if K == 0:
      print(ans + i)
      exit(0)
    elif K < 0:
      print(ans + i -1) 
      exit(0)
  ans += i
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()))
if K < A[0] and K < B[0]:
  print(0)
  exit(0)
if K >= sum(A) + sum(B):
  print(N + M)
  exit(0)
  
ans = -1
a= 0
b= 0
while K >0:
  ans += 1
  if N != a and A[0] <= B[0]:
    a += 1
    K = K - A[0]
    del A[0]
    if K == 0:
      ans += 1
    
  else:
    b +=1
    K = K - B[0]
    del B[0]
    if K == 0:
      ans += 1

print(ans)