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:
def checkWhichToRead(A, B, K, count):
    if K < 0:
        return count - 1
    ACount = count
    BCount = count
    if len(A) > 0:
        ACount = checkWhichToRead(A[1:], B, K - A[0], count + 1)
    if len(B) > 0:
        BCount = checkWhichToRead(A, B[1:], K - B[0], count + 1)
    if ACount > BCount:
        return ACount
    else:
        return BCount


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

print(checkWhichToRead(A, B, K, 0))

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

import numpy as np
A_cumsum = np.cumsum(A)
B_cumsum = np.cumsum(B)
#AB_cumsum = np.sort(np.concatenate([A_cumsum, B_cumsum]))


lenA = len(A)
lenB = len(B)

if lenA < lenB:
    A_cumsum = np.concatenate([A_cumsum, [np.inf]*(lenB-lenA)])
else:
    B_cumsum = np.concatenate([B_cumsum, [np.inf]*(lenA-lenB)])


i = 0
j = 0
t = 0
ans = 0
while i < lenA or j < lenB:
    if A_cumsum[i] < B_cumsum[j]:
        ans += 1
        t += A[i]
        i += 1
    else:
        ans += 1
        t += B[j]
        j += 1
#    print(ans, t)
    if t > K:
        ans -= 1
        break
print(ans)

Submission status: Runtime Error

Solution code:
N, M, K = map(int, input().split())
As = [int(i) for i in input().split()]
Bs = [int(i) for i in input().split()]
x = 0
i = 0
while x < K:
  if(As != [] and Bs != []):
    if(As[0] >= Bs[0]):
      x += Bs.pop(0)
      i += 1
    elif(As[0] < Bs[0]):
      x += As.pop(0)
      i += 1
  elif(As == [] and Bs == []):
	print(i - 1)
  elif(Bs == []):
    x += As.pop(0)
    i += 1
  elif(As == []):
    x += Bs.pop(0)
    i += 1
print(i - 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()))

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

ans, j = 0, m
for i in range(n+1):
    if a[i] > k:
        break
    while [b] > 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[1])
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それぞれについて上から順に加算
A_min = [0]
for i in range(N):
  A_min.append(A_min[i]+A[i])
B_min = [0]
for i in range(M):
  B_min.append(B_min[i]+B[i])

#A_min,B_minを順に加算して、Kを超えていなければ冊数を更新
ans = 0
B_len = len(B_min)
for i in range(len(A_min)):
  if A_min[i] > K:
    break
  while true:
    if B_min[B_len] > K - A_min[i]:
      break
    ans = max(ans,i+B_len)

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それぞれについて上から順に加算
A_min = [0]
for i in range(N):
  A_min.append(A_min[i]+A[i])
B_min = [0]
for i in range(M):
  B_min.append(B_min[i]+B[i])

#A_min,B_minを順に加算して、Kを超えていなければ冊数を更新
ans = 0
B_len = len(B_min)
for i in range(len(A_min)):
  if Amin[i] > K:
    break
  while true:
    if B_min[B_len] > K - A_min[i]:
      break
    ans = max(ans,i+B_len)

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.sort(reverse = True)
b.sort(reverse = True)
cnt = 0
while(min(a[-1],b[-1]) <= k):
    if a[-1] == min(a[-1],b[-1]):
        k = k-min(a[-1],b[-1])
        a.pop()

    else:
        k = k-min(a[-1],b[-1])
        b.pop()

    cnt = cnt+1

print(cnt)

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

sumt = 0
cnt = 0
    
while cnt < (N+M):
    
    if len(A) > 0:
        tmpA = A[0]
    else:
        tmpA = 10**10

    if len(B) > 0:
        tmpB = B[0]
    else:
        tmpA = 10**10

    if tmpA <= tmpB:
        sumt += A.pop(0)
    else:
        sumt += B.pop(0)

    if sumt > K:
        print(cnt)
        exit(0)
        
    cnt += 1
print(cnt)

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

sumt = 0
cnt = 0
    
for i in range(N+M):
    
    if len(A) > 0:
        tmpA = A[0]
    else:
        tmpA = 10**10

    if len(B) > 0:
        tmpB = B[0]
    else:
        tmpA = 10**10

    if tmpA <= tmpB:
        sumt += A.pop(0)
    else:
        sumt += B.pop(0)

    if sumt > K:
        print(cnt)
        exit(0)
        
    cnt += 1
print(cnt)

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

sumt = 0
cnt = 0
Ai = 0
Bi = 0

if (sum(A) + sum(B)) <= K:
    print(N+M)
    exit(0)
    
for i in range(N+M):
    if A[0] <= B[0]:
        sumt += A.pop(0)
    else:
        sumt += B.pop(0)

    if sumt > K:
        print(cnt)
        exit(0)
        
    cnt += 1

Submission status: Runtime Error

Solution code:
A,B,time = map(int,input().split())
list_A = list(map(int,input().split()))
list_B = list(map(int,input().split()))

# print(list_B)

list_A_num = -1
list_B_num = -1

total_time = 0
count = 0

while total_time < time:
    if len(list_A) > 0:
        if list_A[list_A_num] <= list_B[list_B_num]: # Aの値の方が小さければ
            total_time += list_A[list_A_num]
            list_A.pop()
        else:
            total_time += list_B[list_B_num]
            list_B.pop()
    else:
        total_time += list_B[list_B_num]
        list_B.pop()
    if total_time <= time:
        count += 1

print(count)

Submission status: Runtime Error

Solution code:
def get_sum_arr(arr):
    sum_arr = [0]
    N = len(arr)
    for i in range(1,N+1):
        sum_arr.append(sum_arr[i-1] + arr[i-1])
    return sum_arr
    
def get_max_book_num(A,B,K):
    A_sum_arr,B_sum_arr = get_sum_arr(A),get_sum_arr(B)
    count,i,j = 0,0,M
    for i in range(0,len(A_sum_arr)):
        if K < A_sum_arr[i]:
            break
        else:
            while B_sum_arr[j] >= (K - A_sum_arr[i]):
                j -= 1
        count = max(count,(i+j))
    return count

if __name__ == "__main__":
    N,M,K = list(map(int,input().split()))
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    print(get_max_book_num(A,B,K))

Submission status: Runtime Error

Solution code:
def get_sum_arr(arr):
    sum_arr = [0]
    N = len(arr)
    for i in range(1,N+1):
        sum_arr.append(sum_arr[i-1] + arr[i-1])
    return sum_arr
def get_max_book_num(A,B,K):
    A_sum_arr,B_sum_arr = get_sum_arr(A),get_sum_arr(B)
    count,i,j = 0,0,0
    for i in range(0,len(A_sum_arr)):
        if K < A_sum_arr[i]:
            break
        else:
            print("A:",A_sum_arr[:i])
            j = 0
            while B_sum_arr[j] <= (K - A_sum_arr[i]):
                print("B:",B_sum_arr[:j])
                j += 1
                if j >= len(B_sum_arr):
                    break
            j -= 1
        count = max(count,(i+j))
    return count

if __name__ == "__main__":
    N,M,K = list(map(int,input().split()))
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    A_sum_arr,B_sum_arr = get_sum_arr(A),get_sum_arr(B)
    print(get_max_book_num(A,B,K))

Submission status: Runtime Error

Solution code:
def get_sum_arr(arr):
    sum_arr = [0]
    N = len(arr)
    for i in range(1,N+1):
        sum_arr.append(sum_arr[i-1] + arr[i-1])
    return sum_arr
def get_max_book_num(A,B,K):
    A_sum_arr,B_sum_arr = get_sum_arr(A),get_sum_arr(B)
    count,i,j = 0,0,0
    for i in range(0,len(A_sum_arr)):
        if K < A_sum_arr[i]:
            break
        else:
            while (B_sum_arr[j] <= (K - A_sum_arr[i])) and (j < len(B_sum_arr)):
                j += 1
            j -= 1
        count = max(count,(i+j))
    return count

if __name__ == "__main__":
    N,M,K = list(map(int,input().split()))
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    A_sum_arr,B_sum_arr = get_sum_arr(A),get_sum_arr(B)
    print(get_max_book_num(A,B,K))

Submission status: Runtime Error

Solution code:
def get_sum_arr(arr):
    sum_arr = [0]
    N = len(arr)
    for i in range(1,N+1):
        sum_arr.append(sum_arr[i-1] + arr[i-1])
    return sum_arr
def get_max_book_num(A,B,K):
    A_sum_arr,B_sum_arr = get_sum_arr(A),get_sum_arr(B)
    count,i,j = 0,0,0
    for i in range(0,len(A_sum_arr)):
        if K < A_sum_arr[i]:
            break
        else:
            while (B_sum_arr[j] <= (K - A_sum_arr[i])) and (i < len(B_sum_arr)):
                j += 1
            j -= 1
        count = max(count,(i+j))
    return count

if __name__ == "__main__":
    N,M,K = list(map(int,input().split()))
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    A_sum_arr,B_sum_arr = get_sum_arr(A),get_sum_arr(B)
    print(get_max_book_num(A,B,K))

Submission status: Runtime Error

Solution code:
def get_sum_arr(arr):
    sum_arr = [0]
    N = len(arr)
    for i in range(1,N+1):
        sum_arr.append(sum_arr[i-1] + arr[i-1])
    return sum_arr
def get_max_book_num(A,B,K):
    A_sum_arr,B_sum_arr = get_sum_arr(A),get_sum_arr(B)
    count,i,j = 0,0,0
    for i in range(0,len(A_sum_arr)):
        if K < A_sum_arr[i]:
            break
        else:
            while B_sum_arr[j] <= (K - A_sum_arr[i]):
                j += 1
            j -= 1
        count = max(count,(i+j))
    return count

if __name__ == "__main__":
    N,M,K = list(map(int,input().split()))
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    A_sum_arr,B_sum_arr = get_sum_arr(A),get_sum_arr(B)
    print(get_max_book_num(A,B,K))

Submission status: Runtime Error

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
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 j in range(m):
    b_.append(b_[j] + b[j])

ans = 0
j = 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 j in range(m):
    b_.append(b_[j] + b[j])

ans = 0
for i in range(n+1):
    
    idx2 = m
    while a_[i] + b_[idx2] > k:
        idx2 -= 1
    
    ans = max(ans, i + idx2)
print(ans)

Submission status: Runtime Error

Solution code:
N, M, K = [int(v) for v in input().strip().split(" ")]
A = [int(v) for v in input().strip().split(" ")]
B = [int(v) for v in input().strip().split(" ")]

A = [0] + A
B = [0] + B

class Solution():
    def __init__(self):
        self.max_num = 0

    def search(self, now_sum, A_index, B_index, add_axis):
        if add_axis == "A":
            A_index += 1
            if A_index < len(A):
                now_sum += A[A_index]
            else:
                return
        else:
            B_index += 1
            if B_index < len(B):
                now_sum += B[B_index]
            else:
                return

        # print(A_index, B_index, now_sum)

        if A_index + B_index > self.max_num and now_sum <= K:
            self.max_num = A_index + B_index

        if now_sum < K:
            self.search(now_sum, A_index, B_index, "A")
            self.search(now_sum, A_index, B_index, "B")
        else:
            return

    def search_main(self):
        self.search(0, A_index=0, B_index=0, add_axis="A")
        self.search(0, A_index=0, B_index=0, add_axis="B")
        print(self.max_num)

s = Solution()
s.search_main()

Submission status: Runtime Error

Solution code:
n,m,k = map(int,input().split())
nlist = list(map(int,input().split()))
mlist = list(map(int,input().split()))
result = 0

# mlistが読める残り時間。ncount(nが読める冊数)が増えるたびに減少していく
mrest = k

# mlistが読める冊数。最初はの最大冊数だが、ncount(nが読める冊数)が増えるたびに減少していく
mcount = m

# mcount分読むのにかかる時間。最初は最大冊数分持っているか、mcountが減るたびに減少していく
mtime = sum(mlist)

# ncount(nが読める冊数)を1ずつ増やしていく
for ncount in range(0, len(nlist) + 1):
  # mlistが読める残り時間も冊数もあれば、mlistから本を取っていく
  # もしmlistが読める残り時間が最大時間を超えていたら後ろから諦めていく
  while mrest > 0 and mcount > 0 and mtime > mrest:
    mcount -= 1
    mtime -= mlist[mcount]
  # このループで読める冊数はncount+mcount。ループごとの最大値が応え
  result = max(result, ncount + mcount)
  # ncountから1冊読んだので、mrestをその時間分減らす
  mrest -= nlist[ncount]
  # これでmlistを読む時間が無くなってしまったら処理を終了する
  if mrest <= 0:
    break
print(result)

Submission status: Runtime Error

Solution code:
n,m,k = map(int,input().split())
nlist = list(map(int,input().split()))
mlist = list(map(int,input().split()))
result = 0

# mlistが読める残り時間。ncount(nが読める冊数)が増えるたびに減少していく
mrest = sum(mlist)
# mlistが読める冊数。最初はの最大冊数だが、ncount(nが読める冊数)が増えるたびに減少していく
mcount = m

# ncount(nが読める冊数)を1ずつ増やしていく
for ncount in range(0, len(nlist) + 1):
  # mlistが読める残り時間も冊数もあれば、mlistから本を取っていく
  # もしmlistが読める残り時間が最大時間を超えていたら後ろから諦めていく
  while mrest > 0 and mcount > 0 and mrest > k:
    mcount -= 1
    mrest -= mlist[mcount - 1]
  # このループで読める冊数はncount+mcount。ループごとの最大値が応え
  result = max(result, ncount + mcount)
  # ncountから1冊読んだので、mrestをその時間分減らす
  mrest -= nlist[ncount]
  # これでmlistを読む時間が無くなってしまったら処理を終了する
  if mrest <= 0:
    break
print(result)

Submission status: Runtime Error

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

n = 0
m = 0
r = 0
while n < len(nn) or m < len(mm):
  if (m == len(mm) or nn[n] < mm[m]) and n < len(nn):
    if k < nn[n]:
      break
    k -= nn[n]
    r += 1
    n += 1
  else:
    if k < mm[m]:
      break
    r += 1
    m += 1
print(r)

Submission status: Runtime Error

Solution code:
N,M,K = (int(x) for x in input().split())
A = list(map(int, input.split()))
B = list(map(int, input.split()))
i,j = 0
time = 0
while time < K and i < N-1 or j < M-1:
    if A[i] < B[j]:
        time += A[i]
        i += 1
    elif A[i] > B[j]:
        time += B[j]
        j += 1
allbooks = i + j
print(allbooks)

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])
  print(a)
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 = input().split()
B = input().split()

index = 0
readingTime = 0
counter = 0
for i in range(len(A)):
    K -= int(A[i])
    if K > 0:
        counter += 1
    else:
        break
    for j in range(len(B)):
        K -= int(B[i])
        if K > 0:
            counter += 1
        else:
            break
        
print(counter)

Submission status: Runtime Error

Solution code:
if __name__ == "__main__":
    N,M,K = list(map(int,input().split()))
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    count,i_a,i_b = 0,0,0
    # ADD A item
    for i_a in range(len(A)):
        if K < A[i_a]:
            i_a -= 1
            break
        else:
            K -= A[i_a]
    # replace B item
    for i_b in range(len(B)):
        if K < B[i_b] :
            i_b -= 1
            break
        else :
            K -= B[i_b]
    
    count = (i_a+1) + (i_b+1) # 読んだ本のindexの次のindexが格納されている。
    # 1冊も読めない⇒0
    # idx = i_a,i_bまで読んだ。
    # forの繰り返しをすべて終えた時 +1されるのか?

    for i in range(i_a,-1,-1): # A のアイテムを1つずつ減らしていく。
        K += A[i]
        for j in range(i_b,len(B)):
            if K < B[i_b]:
                i_b -= 1
            else :
                K -= B[i_b]
        count = max(count,((i)+(i_b+1)))
    print(count)

Submission status: Runtime Error

Solution code:
N, M, K = map(int, input().split())
As = [int(i) for i in input().split()]
Bs = [int(i) for i in input().split()]
x = 0
i = 0
tmp = 0
if (N > 0 and M > 0):
  while x < K:
    if(tmp > 0):
      if(As[i - tmp] >= Bs[i]):
        x += Bs[i]
        tmp += 1
      else:
        x += As[i - tmp]
        tmp -= 1
    elif(tmp == 0):
      if(As[i] >= Bs[i]):
        x += Bs[i]
        tmp += 1
      else:
        x += As[i]
        tmp -= 1
    elif(tmp < 0):
      if(As[i] >= Bs[i + tmp]):
        x += Bs[i]
        tmp += 1
      else:
        x += As[i + tmp]
        tmp -= 1
    i = i + 1
  if(i == 1):
    print(0)
  else:
    print(i - 1)
elif(N == 0 and M > 0):
  while x < K:
    x += Bs[i]
    i += 1
  if(i == 1):
    print(0)
  else:
    print(i - 1)
elif(N > 0 and M == 0):
  while x < K:
    x += As[i]
    i += 1
  if(i == 1):
    print(0)
  else:
    print(i - 1)

Submission status: Runtime Error

Solution code:
N, M, K = map(int, input().split())
As = [int(i) for i in input().split()]
Bs = [int(i) for i in input().split()]
x = 0
i = 0
tmp = 0
if (N > 0 and M > 0):
  while x < K:
    if(tmp > 0):
      if(As[i - tmp] >= Bs[i]):
        x += Bs[i]
        tmp += 1
      else:
        x += As[i - tmp]
        tmp -= 1
    elif(tmp == 0):
      if(As[i] >= Bs[i]):
        x += Bs[i]
        tmp += 1
      else:
        x += As[i]
        tmp -= 1
    elif(tmp < 0):
      if(As[i] >= Bs[i + tmp]):
        x += Bs[i]
        tmp += 1
      else:
        x += As[i + tmp]
        tmp -= 1
    i = i + 1
elif(N == 0 and M > 0):
  while x < K:
    x += Bs[i]
    i += 1
elif(N > 0 and M == 0):
  while x < K:
    x += As[i]
    i += 1
if(i == 1):
  print(0)
else:
  print(i)

Submission status: Runtime Error

Solution code:
N, M, K = map(int, input().split())
As = [int(i) for i in input().split()]
Bs = [int(i) for i in input().split()]
x = 0
i = 0
tmp = 0
if (N > 0 and M > 0):
  while x < K:
    if(tmp > 0):
      if(As[i - tmp] >= Bs[i]):
        x += Bs[i]
        tmp += 1
      else:
        x += As[i - tmp]
        tmp -= 1
    elif(tmp == 0):
      if(As[i] >= Bs[i]):
        x += Bs[i]
        tmp += 1
      else:
        x += As[i]
        tmp -= 1
    elif(tmp < 0):
      if(As[i] >= Bs[i + tmp]):
        x += Bs[i]
        tmp += 1
      else:
        x += As[i + tmp]
        tmp -= 1
    i = i + 1
elif(N == 0 and M > 0):
  while x < K:
    x += Bs[i]
    i += 1
elif(N > 0 and M == 0):
  while x < K:
    x += As[i]
    i += 1
if(i == 1):
  print(0)
else:
  print(i - 1)

Submission status: Runtime Error

Solution code:
N, M, K = map(int, input().split())
As = [int(i) for i in input().split()]
Bs = [int(i) for i in input().split()]
x = 0
i = 0
tmp = 0
while x < K:
  if(tmp > 0):
    if(As[i - tmp] >= Bs[i]):
      x += Bs[i]
      tmp += 1
    else:
      x += As[i - tmp]
      tmp -= 1
  elif(tmp == 0):
    if(As[i] >= Bs[i]):
      x += Bs[i]
      tmp += 1
    else:
      x += As[i]
      tmp -= 1
  elif(tmp < 0):
    if(As[i] >= Bs[i + tmp]):
      x += Bs[i]
      tmp += 1
    else:
      x += As[i + tmp]
      tmp -= 1
  i = i + 1
if(i == 1):
  print(0)
else:
  print(i - 1)

Submission status: Runtime Error

Solution code:
N, M, K = map(int, input().split())
As = [int(i) for i in input().split()]
Bs = [int(i) for i in input().split()]
x = 0
i = 0
tmp = 0
while x < K:
  if(tmp > 0):
    if(As[i] >= Bs[i - tmp]):
      x += Bs[i - tmp]
      tmp -= 1
    else:
      x += As[i]
      tmp += 1
  elif(tmp == 0):
    if(As[i] >= Bs[i]):
      x += Bs[i]
      tmp -= 1
    else:
      x += As[i]
      tmp += 1
  elif(tmp < 0):
    if(As[i + tmp] >= Bs[i]):
      x += Bs[i]
      tmp -= 1
    else:
      x += As[i + tmp]
      tmp += 1
  i = i + 1
if(i == 1):
  print(0)
else:
  print(i - 1)

Submission status: Runtime Error

Solution code:
N, M, K = map(int, input().split())
As = [int(i) for i in input().split()]
Bs = [int(i) for i in input().split()]
x = 0
i = 0
tmp = 0
while x < K:
  if(tmp > 0):
    if(As[i] >= Bs[i - tmp]):
      x += Bs[i - tmp]
      tmp -= 1
    else:
      x += As[i]
      tmp += 1
  elif(tmp == 0):
    if(As[i] >= Bs[i]):
      x += Bs[i]
      tmp -= 1
    else:
      x -= As[i]
      tmp += 1
  elif(tmp < 0):
    if(As[i + tmp] >= Bs[i]):
      x += Bs[i]
      tmp -= 1
    else:
      x += As[i + tmp]
      tmp += 1
  i = i + 1
if(i == 1):
  print(0)
else:
  print(i - 1)

Submission status: Runtime Error

Solution code:
N, M, K = map(int, input().split())
As = [int(i) for i in input().split()]
Bs = [int(i) for i in input().split()]
x = 0
i = 0
tmp = 0
while x < K:
  if(tmp > 0):
    if(As[i] >= Bs[i - tmp]):
      x += Bs[i - tmp]
      tmp += 1
    else:
      x += As[i]
      tmp -= 1
  elif(tmp == 0):
    if(As[i] >= Bs[i]):
      x += Bs[i]
      tmp += 1
    else:
      x -= As[i]
      tmp += 1
  elif(tmp < 0):
    if(As[i + tmp] >= Bs[i]):
      x += Bs[i]
      tmp += 1
    else:
      x += As[i + tmp]
      tmp -= 1
  i = i + 1
if(i == 1):
  print(0)
else:
  print(i - 1)

Submission status: Runtime Error

Solution code:
3 4 240
100 160 120
80 150 80 150

Submission status: Runtime Error

Solution code:
N, M, K = map(int, input().split())
As = [int(i) for i in input().split()]
Bs = [int(i) for i in input().split()]
x = 0
i = 0
tmp = 0
while x < K:
  if(tmp > 0):
    if(As[i] >= Bs[i - tmp]):
      x += Bs[i]
      tmp -= 1
    else:
      x += As[i]
      tmp += 1
  elif(tmp == 0):
    if(As[i] >= Bs[i]):
      x += Bs[i]
      tmp -= 1
    else:
      x += As[i]
      tmp += 1
  elif(tmp < 0):
    if(As[i + tmp] >= Bs[i]):
      x += Bs[i]
      tmp -= 1
    else:
      x += As[i + tmp]
      tmp += 1
  i = i + 1
if(i == 1):
  print(0)
else:
  print(i - 1)

Submission status: Runtime Error

Solution code:
N, M, K = map(int, input().split())
As = [int(i) for i in input().split()]
Bs = [int(i) for i in input().split()]
x = 0
i = 0
tmpA = 0
tmpB = 0
while x < K:
  if(tmpA > 0 and tmpB == 0):
    if(As[i - tmpA] >= Bs[i - tmpB]):
      x += Bs[i - tmpB]
      tmpA = tmpA + 1
    else:
      x += As[i - tmpA]
      tmpA = tmpA - 1
  elif(tmpA == 0 and tmpB == 0):
    if(As[i] >= Bs[i]):
      x += Bs[i]
      tmpA = tmpA + 1
    else:
      x += As[i]
      tmpB = tmpB + 1
  elif(tmpA == 0 and tmpB > 0):
    if(As[i - tmpA] >= Bs[i - tmpB]):
      x += Bs[i - tmpB]
      tmpB = tmpB - 1
    else:
      x += As[i - tmpA]
      tmpB = tmpB + 1
  i = i + 1
if(i == 1):
  print(0)
else:
  print(i - 1)

Submission status: Runtime Error

Solution code:
N, M, K = map(int, input().split())
As = [int(i) for i in input().split()]
Bs = [int(i) for i in input().split()]
x = 0
i = 0
tmpA = 0
tmpB = 0
while x < K:
  if(tmpA > 0 and tmpB == 0):
    if(As[i - tmpA] >= Bs[i - tmpB]):
      x += Bs[i - tmpB]
      tmpA = tmpA + 1
    else:
      x += As[i - tmpA]
      tmpA = tmpA - 1
  elif(tmpA == 0 and tmpB == 0):
    if(As[i] >= Bs[i]):
      x += Bs[i]
      tmpA = tmpA + 1
    else:
      x += As[i]
      tmpB = tmpB + 1
  elif(tmpA == 0 and tmpB > 0):
    if(As[i - tmpA] >= Bs[i - tmpB]):
      x += Bs[i - tmpB]
      tmpB = tmpB - 1
    else:
      x += As[i - tmpA]
      tmpB = tmpB + 1
  i = i + 1
if(i == 0):
  print(0)
else:
  print(i - 1)

Submission status: Runtime Error

Solution code:
N, M, K = map(int, input().split())
As = [int(i) for i in input().split()]
Bs = [int(i) for i in input().split()]
x = 0
i = 0
tmpA = 0
tmpB = 0
while x < K:
  if(tmpA > 0 and tmpB == 0):
    if(As[i - tmpA] >= Bs[i - tmpB]):
      x += Bs[i]
      tmpA = tmpA + 1
    else:
      x += As[i]
      tmpA = tmpA - 1
  elif(tmpA == 0 and tmpB == 0):
    if(As[i - tmpA] >= Bs[i - tmpB]):
      x += Bs[i]
      tmpA = tmpA + 1
    else:
      x += As[i]
      tmpB = tmpB + 1
  elif(tmpA == 0 and tmpB > 0):
    if(As[i - tmpA] >= Bs[i - tmpB]):
      x += Bs[i]
      tmpB = tmpB - 1
    else:
      x += As[i]
      tmpB = tmpB + 1
  i = i + 1
if(i == 0):
  print(0)
else:
  print(i)

Submission status: Runtime Error

Solution code:
N, M, K = map(int, input().split())
As = [int(i) for i in input().split()]
Bs = [int(i) for i in input().split()]
x = 0
i = 0
tmpA = 0
tmpB = 0
while x < K:
  if(As[i - tmpA] >= Bs[i - tmpB]):
    x += Bs[i]
    tmpA = tmpA + 1
  else:
    x += As[i]
    tmpB = tmpB + 1
  i = i + 1
if(i == 0):
  print(0)
else:
  print(i)

Submission status: Runtime Error

Solution code:
N, M, K = map(int, input().split())
As = [int(i) for i in input().split()]
Bs = [int(i) for i in input().split()]
x = 0
i = 0
tmpA = 0
tmpB = 0
while x < K:
  if(As[i - tmpA] >= Bs[i - tmpB]):
    x += Bs[i]
    tmpA = tmpA + 1
  else:
    x += As[i]
    tmpB = tmpB + 1
  i = i + 1
print(i)

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

total_read_time = 0
num_read_books = 0
for i in range(N+M):
    if A == [] and B == []:
        break
    elif A == [] and B != []:
        read_book_time = B[0]
    elif B == [] and A != []:
        read_book_time = A[0]
    elif A[0] <= B[0]:
        read_book_time = A[0]
    else:
        read_book_time = B[0]

    if read_book_time == B[0]:
        del B[0]
    elif read_book_time == A[0]:
        del A[0]

    total_read_time += read_book_time
    if total_read_time > K:
        break
    num_read_books += 1

print(num_read_books)

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()))
ta=0
tb=0
ans=0
for i in range(n+1):
    ta += a[i]
    if i=0:
        ta=0
    if ta>k:
        break
    for j in range(m):
        tb=sum(b[:j+1])
        ans=max(ans,i+j)
        if tb + ta >k:
            break
        ans=max(ans,i+j+1)
print(ans)