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: Wrong Answer

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

totalA = [0]
totalB = [0]
sumA = 0
for i in range(N):
    sumA += A[0]
    totalA.append(sumA)
sumB = 0
for i in range(M):
    sumB += B[0]
    totalB.append(sumB)

iB = M
countMax = 0
for iA in range(N+1):
  if totalA[iA]>K:
    break
  else:
    while totalA[iA] + totalB[iB] > K:
      iB -= 1
  countMax = max(countMax,iA+iB)

print(countMax)

Submission status: Wrong Answer

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

totalA = [0]
totalB = [0]
sumA = 0
for i in range(N):
    sumA += A[0]
    totalA.append(sumA)
sumB = 0
for i in range(M):
    sumB += B[0]
    totalB.append(sumB)

iA = N
iB = 0
countMax = 0
while iA >= 0:
    if totalA[iA] + totalB[iB] > K:
        iA -= 1
    else:
        while totalA[iA] + totalB[iB] <= K:
          countMax = max(countMax,iA+iB)
          if iB == M:
            break
          iB += 1
    if iA == N and iB == M:
      break
          
print(countMax)

Submission status: Wrong Answer

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

totalA = [0]
totalB = [0]
sumA = 0
for i in range(N):
    sumA += A[0]
    totalA.append(sumA)
sumB = 0
for i in range(M):
    sumB += B[0]
    totalB.append(sumB)

iA = N
iB = 0
countMax = 0
while iA >= 0:
    if totalA[iA] + totalB[iB] > K:
        iA -= 1
    else:
        if iB < M:
            countMax = max(countMax, iA + iB)
            iB += 1
    if iA == N and iB == M:
        countMax = max(countMax, iA + iB)
        break

print(countMax)

Submission status: Wrong Answer

Solution code:


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

As = list(map(int,input().split()))
Bs = list(map(int,input().split()))

As_sum = [0]
Bs_sum = [0]

answer = 0

for i in range(N):
    As_sum.append(As_sum[i]+As[i])
for i in range(M):
    Bs_sum.append(Bs_sum[i]+Bs[i])

answer = 0
j = M

for i in range(len(As_sum)):
    if As_sum[i] < K:
        break
    while Bs_sum[j] > K - As_sum[i]:
        j -= 1
    answer = max(answer, i+j)

print(answer)

Submission status: Wrong Answer

Solution code:
def checkWhichToRead(A, B):
    if len(A) == 0:
        return 1
    elif len(B) == 0:
        return 0
    elif A[-1] > B[-1]:
        return 1
    elif A[-1] < B[-1]:
        return 0
    else:
        return checkWhichToRead(A[0:-1], B[0:-1])


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

count = 0
while K >= 0:
    if checkWhichToRead(A, B):
        K -= B.pop()
    else:
        K -= A.pop()
    count += 1
    if count == N + M:
        count += 1
        break
print(count - 1)

Submission status: Wrong Answer

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

for x in range(N-1):
    A[x+1] += A[x]
    if A[x+1] > K:
        A = [0] + A[:x+1]
        break

for y in range(M-1):
    B[y+1] += B[y]
    if B[y+1] > K:
        B = [0] + B[:y+1]
        break

na = len(A)
nb = len(B) 

if A[-1] + B[-1] <= K:
    answer = len(A) + len(B)
    print(answer)

else:
    for i in range(na):
        for j in range(nb-b_ind-1, -1, -1):
            if A[i] + B[j] <= K:
                if answer < i+j:
                    answer = i+j
                b_ind = nb-j-1
                break
    print(answer)

Submission status: Wrong Answer

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

for x in range(N-1):
    A[x+1] += A[x]
    if A[x+1] > K:
        A = [0] + A[:x+1]
        break

for y in range(M-1):
    B[y+1] += B[y]
    if B[y+1] > K:
        B = [0] + B[:y+1]
        break

na = len(A)
nb = len(B) 

if A[-1] + B[-1] <= K:
    answer = len(A) + len(B)
    print(answer)

else:
    for i in range(na):
        for j in range(nb-b_ind-1, -1, -1):
            if A[i] + B[j] <= K:
                if answer < i+j:
                    answer = i+j
                b_ind += nb-j-1
                break
    print(answer)

Submission status: Wrong Answer

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

for x in range(N-1):
    A[x+1] += A[x]
    if A[x+1] > K:
        A = [0] + A[:x+1]
        break

for y in range(M-1):
    B[y+1] += B[y]
    if B[y+1] > K:
        B = [0] + B[:y+1]
        break

if A[-1] + B[-1] <= K:
    answer = len(A) + len(B)
    print(answer)

else:
    for i in range(len(A)):
        for j in range(len(B)):
            if A[i] + B[j] > K:
                if answer < i+j-1:
                    answer = i+j-1
                break
    print(answer)

Submission status: Wrong Answer

Solution code:
n,m,k=[*map(int,input().split())]
a=[*map(int,input().split())]
b=[*map(int,input().split())]
count=0
while k>0:
  if k<=0:
    break
  elif len(a)==0 and len(b)==0:
    break
  else:
    if len(a)!=0 and len(b)!=0:
      if a[0]<b[0]:
        if k-a[0]>=0:
          k-=a[0]
          count+=1
          a.remove(a[0])
        else:
          break
      else:
        if k-b[0]>=0:
          k-=b[0]
          count+=1
          b.remove(b[0])
        else:
          break
    elif len(a)==0:
      if k-b[0]>=0:
          k-=b[0]
          count+=1
          b.remove(b[0])
      else:
          break
    elif len(b)==0:
        if k-a[0]>=0:
          k-=a[0]
          count+=1
          a.remove(a[0])
        else:
          break
print(count)

Submission status: Wrong Answer

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

A_now = 0
B_now = 0
time = 0
answer = 0
if sum(A) + sum(B) <= K:
    print(N + M)

else:
     while time < K:
        if A_now >= N:
            time += B[B_now]
            B_now += 1
            

        elif B_now >= M:
            time += A[A_now]
            A_now += 1
        
        elif A[A_now] >= B[B_now]:
            time += B[B_now]
            B_now += 1

        else:
            time += A[A_now]
            A_now += 1
        
        answer += 1

     print(answer - 1)

Submission status: Wrong Answer

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

arr=list(map(int,input().strip().split()))
arr.extend(list(map(int,input().strip().split())))
arr.sort()
i=0
re=0
x=[]
while(k>0):
    if(k>=arr[i]):
        k-=arr[i]
        re+=1
        i+=1
    else:
        break
    
print(re)

Submission status: Wrong Answer

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, [max(B_cumsum)+1]])
else:
    B_cumsum = np.concatenate([B_cumsum, [max(A_cumsum)+1]])

#print(A_cumsum)
#print(B_cumsum)


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]
#        print(ans, 'a', i, A[i], t)
        i += 1
    else:
        ans += 1
        t += B[j]
#        print(ans, 'b', j, B[j], t)
        j += 1
#    print(i,j)
    if t > K:
        ans -= 1
        break
print(ans)

Submission status: Wrong Answer

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, [max(B_cumsum)+1]])
else:
    B_cumsum = np.concatenate([B_cumsum, [max(A_cumsum)+1]])

print(A_cumsum)
print(B_cumsum)


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)
#    print(i,j)
    if t > K:
        ans -= 1
        break
print(ans)

Submission status: Wrong Answer

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]])
else:
    B_cumsum = np.concatenate([B_cumsum, [np.inf]])


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: Wrong Answer

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
y = 0
i = 0
min = 0
if(N != 0 and M != 0):
  for x in range(N):
    min += As[x]
    i += 1
    if(min > K):
      break
    for y in range(M):
      min += Bs[y]
      i += 1
      if(min > K):
        break
elif(N == 0 and M != 0):
  for y in range(M):
    min += Bs[y]
    i += 1
    if(min > K):
      break
elif(N != 0 and M == 0):
  for x in range(N):
    min += As[x]
    i += 1
    if(min > K):
      break
elif(N == 0 and M == 0):
  print(0)
print(i - 1)

Submission status: Wrong Answer

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
y = 0
i = 0
min = 0
if(N != 0 and M != 0):
  for x in range(N):
    min += As[x]
    i += 1
    if(min > K):
      break
    for y in range(M):
      min += Bs[y]
      i += 1
      if(min > K):
        break
elif(N == 0 and M != 0):
  for y in range(M):
    min += Bs[y]
    i += 1
    if(min > K):
      break
elif(N != 0 and M == 0):
  for y in range(N):
    min += As[x]
    i += 1
    if(min > K):
      break
elif(N == 0 and M == 0):
  print(0)
print(i - 1)

Submission status: Wrong Answer

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
y = 0
i = 0
min = 0
for x in range(N):
  min += As[x]
  i += 1
  if(min > K):
    break
  for y in range(M):
    min += Bs[y]
    i += 1
    if(min > K):
      break
print(i)

Submission status: Wrong Answer

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(len(As) != 0 and len(Bs) != 0):
    if(As[0] >= Bs[0]):
      x += Bs.pop(0)
      i += 1
    elif(As[0] < Bs[0]):
      x += As.pop(0)
      i += 1
  elif(len(As) == 0 and len(Bs) == 0):
    print(i)
  elif(len(Bs) == 0):
    x += As.pop(0)
    i += 1
  elif(len(As) == 0):
    x += Bs.pop(0)
    i += 1
print(i - 1)

Submission status: Wrong Answer

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(len(As) != 0 and len(Bs) != 0):
    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(len(Bs) == 0):
    x += As.pop(0)
    i += 1
  elif(len(As) == 0):
    x += Bs.pop(0)
    i += 1
print(i - 1)

Submission status: Wrong Answer

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: Wrong Answer

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 == []):
    x += Bs.pop(0)
    i += 1
  elif(Bs == []):
    x += As.pop(0)
    i += 1
print(i - 1)

Submission status: Wrong Answer

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

asum = sum(A)
bsum = sum(B)
max_count = 0

for i in range(N+1):
    total = sum(A[0:i])
    count = i if total <= K else 0

    for j in range(M):
        if total + B[j] <= K:
            total += B[j]
            count += 1

            if max_count < count:
                max_count = count
        else:
            break

print(max_count)

Submission status: Wrong Answer

Solution code:
n,m,k=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]

cnt_max=0

pat="A"*n+"B"*m
import itertools as it

for buf in set(it.permutations(pat)):
  print(buf)
  kb=k
  ai=0
  bi=0
  cnt=0
  for c in buf:
    if c=="A":
      if kb>=a[ai]:
        kb-=a[ai]
 #       print(a[ai])
        cnt+=1
        ai+=1
      else:
        break
    else:
      if kb>=b[bi]:
        kb-=b[bi]
        cnt+=1
        bi+=1
      else:
        break
#  print(cnt)
  if cnt_max<cnt:
    cnt_max=cnt

print(cnt_max)

Submission status: Wrong Answer

Solution code:
[n,m,k] = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
count = 0
if n < m:
  for i in range(n):
    k -= a[i]
    count += 1
    if k < 0:
      count -= 1
      break
    k -= b[i]
    count += 1
    if k < 0:
      count -= 1
      break
  for i in range(n,m):
    k -= b[i]
    count += 1
    if k < 0:
      count -= 1
      break
else:
  for i in range(m):
    k -= a[i]
    count += 1
    if k < 0:
      count -= 1
      break
    k -= b[i]
    count += 1
    if k < 0:
      count -= 1
      break
  for i in range(m,n):
    k -= a[i]
    count += 1
    if k < 0:
      count -= 1
      break  
print(count)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from bisect import bisect_right
# Kは読める時間。この時間を最大に使ってたくさん本を読みたい
N, M, K = map(int, input().split())

a_books = list(map(int, input().split()))
b_books = list(map(int, input().split()))
a_books = list(accumulate(a_books))
b_books = list(accumulate(b_books))

a_index = bisect_right(a_books, K)
b_index = bisect_right(b_books, K)


# print(a_books)
# print(b_books)
# print(a_index, b_index)

max_nums = 0
for i in range(a_index):
    for j in range(b_index):
        if a_books[i] + b_books[j] <= K:
            max_nums = max(max_nums, i + j + 2)
print(max_nums)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
# Kは読める時間。この時間を最大に使ってたくさん本を読みたい
N, M, K = map(int, input().split())

a_books = list(map(int, input().split()))
b_books = list(map(int, input().split()))
a_books = list(accumulate(a_books))
b_books = list(accumulate(b_books))
# print(a_books)
# print(b_books)
max_nums = 0
for i in range(N):
    if a_books[i] > K:
        break
    # print(i)
    for j in range(M):
        if a_books[i] + b_books[j] > K:
            break
        # print(i, j)
        max_nums = max(max_nums, i + 1 + j + 1)
print(max_nums)

Submission status: Wrong Answer

Solution code:
import bisect
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = A[0]
b = B[0]
a_lis = [0,a]
b_lis = [b]
for i in range(1,N):
    a += A[i]
    a_lis.append(a)
for j in range(1,M):
    b += B[j]
    b_lis.append(b)
ans = 0
for i in range(N+1):
    j = bisect.bisect_right(b_lis,K-a_lis[i])
    tmp_ans = i + j 
    if ans < tmp_ans:
        ans = tmp_ans
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = A[0]
b = B[0]
a_lis = [a]
b_lis = [b]
for i in range(1,N):
    a += A[i]
    a_lis.append(a)
for j in range(1,M):
    b += B[j]
    b_lis.append(b)
ans = 0
for i in range(N):
    j = bisect.bisect_right(b_lis,K-a_lis[i])
    tmp_ans = i + j + 1
    if ans < tmp_ans:
        ans = tmp_ans
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

n,m,k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
Acum = [A[0]] + [0]*(n-1)
Bcum = [B[0]] + [0]*(m-1)
for i in range(1,n):
    Acum[i] = Acum[i-1] + A[i]
for i in range(1,m):
    Bcum[i] = Bcum[i-1] + B[i]
maxn = 0
Bcum = [0] + Bcum
for i in range(m+1):
    if Bcum[i] < k:
        maxn = max(maxn,i + bisect.bisect_right(Acum, k-Bcum[i]))

print(maxn)

Submission status: Wrong Answer

Solution code:
import bisect

n,m,k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
Acum = [A[0]] + [0]*(n-1)
Bcum = [B[0]] + [0]*(m-1)
for i in range(1,n):
    Acum[i] = Acum[i-1] + A[i]
for i in range(1,m):
    Bcum[i] = Bcum[i-1] + B[i]
maxn = 0
for i in range(m):
    if Bcum[i] < k:
        maxn = max(maxn,i + 1 + bisect.bisect_left(Acum, k-Bcum[i]))

print(maxn)

Submission status: Wrong Answer

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

i, j = 0, 0
ans = 0

while True:
  if i>=len(A):
    if j>=len(B):
      break
    elif K<B[j]:
      break
    else:
      K -= B[j]
      j += 1
      ans += 1
  elif j>=len(B):
    if K<A[i]:
      break
    else:
      K -= A[i]
      i += 1
      ans += 1
  elif A[i]<=B[j]:
    if K<A[i]:
      break
    else:
      K -= A[i]
      i += 1
      ans += 1
  else:
    if K<B[j]:
      break
    else:
      K -= B[j]
      j += 1
      ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

n,m,k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
Acum = [A[0]] + [0]*(n-1)
Bcum = [B[0]] + [0]*(m-1)
for i in range(1,n):
    Acum[i] = Acum[i-1] + A[i]
for i in range(1,m):
    Bcum[i] = Bcum[i-1] + B[i]
maxn = 0
for i in range(m):
    if Bcum[i] < k:
        maxn = max(maxn,i + 1 + bisect.bisect_right(Acum, k-Bcum[i]))

print(maxn)

Submission status: Wrong Answer

Solution code:
from _collections import deque
n,m,k=map(int,input().split())
A=deque(list(map(int,input().split())))
B=deque(list(map(int,input().split())))

t=0
ans=0
while True:
    if (not A) and (not B):
        break
    elif not A:
        t+=B.popleft()
    elif not B:
        t+=A.popleft()
    else:
        if A[0]<B[0]:
            t+=A.popleft()
        else:
            t+=B.popleft()
    if t>k:
        break
    ans+=1
print(ans)

Submission status: Wrong Answer

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

t=0
ans=0
while True:
    if (not A) and (not B):
        break
    elif not A:
        t+=B.pop(0)
    elif not B:
        t+=A.pop(0)
    else:
        if A[0]<B[0]:
            t+=A.pop(0)
        else:
            t+=B.pop(0)
    if t>k:
        break
    ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
number=list(map(int,input().split()))
N,M,K=number[0],number[1],number[2]
A=list(map(int,input().split()))
B=list(map(int,input().split()))
answer=0
j=M
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
    while b[j]>K-a[i]:
        j-=1
    answer=max(answer,i+j)
print(answer)

Submission status: Wrong Answer

Solution code:
number=list(map(int,input().split()))
N,M,K=number[0],number[1],number[2]
A=list(map(int,input().split()))
B=list(map(int,input().split()))
answer=0
j=M
for i in range(N):
    if sum(A[:i])>K:
        break
    while sum(B[:j])>K-sum(A[:i]):
        j-=1
    answer=max(answer,i+j)
print(answer)

Submission status: Wrong Answer

Solution code:
a, b, c = map(int, input().split())
d = 0
list1 = list(map(int, input().split()))
list2 = list(map(int, input().split()))
e = 0
listing = 1

while c > d:
    e += 1
    if list1 and listing == 1:
        d += list1[0]
        del list1[0]
        listing = 2
    elif list2 and listing == 2:
        d += list2[0]
        del list2[0]
        listing = 1
    elif list2 and not list1:
        d += list2[0]
        del list2[0]
    elif list1 and not list2:
        d += list1[0]
        del list1[0]
    else:
        break
if c <= d:
    e -= 1
print(e)

Submission status: Wrong Answer

Solution code:
a, b, c = map(int, input().split())
d = 0
list1 = list(map(int, input().split()))
list2 = list(map(int, input().split()))
e = 0
listing = 1

while c >= d:
    e += 1
    if list1 and listing == 1:
        d += list1[0]
        del list1[0]
        listing = 2
    elif list2 and listing == 2:
        d += list2[0]
        del list2[0]
        listing = 1
    elif list2 and not list1:
        d += list2[0]
        del list2[0]
    elif list1 and not list2:
        d += list1[0]
        del list1[0]
    else:
        break
if c < d:
    e -= 1
print(e)

Submission status: Wrong Answer

Solution code:
a, b, c = map(int, input().split())
d = 0
list1 = list(map(int, input().split()))
list2 = list(map(int, input().split()))
e = 0
listing = 1

while c > d:
    e += 1
    if list1 and listing == 1:
        d += list1[0]
        del list1[0]
        listing = 2
    elif list2 and listing == 2:
        d += list2[0]
        del list2[0]
        listing = 1
    elif list2 and not list1:
        d += list2[0]
        del list2[0]
    elif list1 and not list2:
        d += list1[0]
        del list1[0]
    else:
        break
if c < d:
    e -= 1
print(e)

Submission status: Wrong Answer

Solution code:
a, b, c = map(int, input().split())
d = 0
list1 = list(map(int, input().split()))
list2 = list(map(int, input().split()))
e = 0
listing = 1

while c > d:
    e += 1
    if list1 and listing == 1:
        d += list1[0]
        del list1[0]
        listing = 2
    elif list2 and listing == 2:
        d += list2[0]
        del list2[0]
        listing = 1
if c < d:
    e -= 1
print(e)

Submission status: Wrong Answer

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

sum_time = 0
book_num = 0
while sum_time < k:
    # 片方しかない場合
    if len(A) == 0:
        sum_time += B[0]
        book_num += 1
        B.pop(0)
        continue
    elif len(B) == 0:
        sum_time += A[0]
        book_num += 1
        A.pop(0)
        continue

    if min(A[0], B[0]) > k - sum_time:
        break
    if A[0] < B[0]:
        sum_time += A[0]
        book_num += 1
        A.pop(0)
        continue
    elif B[0] < A[0]:
        sum_time += B[0]
        book_num += 1
        B.pop(0)
        continue

    # 最小値が同じ場合
    a_i = 0
    b_i = 0
    while A[a_i] == B[b_i]:
        if A[a_i] < B[b_i]:
            sum_time += A[0]
            book_num += 1
            A.pop(0)
            break
        elif A[a_i] > B[b_i]:
            sum_time += B[0]
            book_num += 1
            B.pop(0)
            break

        a_i += 1
        b_i += 1
        if a_i >= len(A):
            a_i = -1
        if b_i >= len(B):
            b_i = -1

print(book_num)

Submission status: Wrong Answer

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

sum_time = 0
book_num = 0
while sum_time < k:
    # 片方しかない場合
    if len(A) == 0:
        sum_time += B[0]
        book_num += 1
        B.pop(0)
        continue
    elif len(B) == 0:
        sum_time += A[0]
        book_num += 1
        A.pop(0)
        continue

    min_v = min(A[0], B[0])
    if min_v > k - sum_time:
        break
    if A[0] < B[0]:
        sum_time += A[0]
        book_num += 1
        A.pop(0)
        continue
    elif B[0] < A[0]:
        sum_time += B[0]
        book_num += 1
        B.pop(0)
        continue

    # 最小値が同じ場合
    a_i = 0
    b_i = 0
    while A[a_i] != B[b_i]:
        if A[a_i] < B[b_i]:
            sum_time += A[0]
            book_num += 1
            A.pop(0)
            break
        elif A[a_i] > B[b_i]:
            sum_time += B[0]
            book_num += 1
            B.pop(0)
            break

        a_i += 1
        b_i += 1
        if a_i >= len(A):
            a_i = -1
        if b_i >= len(B):
            b_i = -1

print(book_num)

Submission status: Wrong Answer

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

N,M,K =map(int,"5 7 100".split())
A = [10,10,20,30,3]
B = [3,9,30,20,1,7,20]

#読書時間を机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 = M
for i in range(len(A_min)):
  if A_min[i] > K:
    break
  while B_min[B_len] > K - A_min[i]:
    B_len -= 1
  ans = max(ans,i+B_len)
print(ans)

Submission status: Wrong Answer

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 = M
for i in range(len(A_min)):
  print("i=",str(i))
  if A_min[i] > K:
    break
  while B_min[B_len] > K - A_min[i]:
    print("B_len=",str(B_len))
    print("A_min=",str(A_min[i]))
    print("B_min=",str(B_min[B_len]))
    ans = max(ans,i+B_len)
    B_len -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n,m,k = inpm()
a = [0] + inpl()
b = [0] + inpl()
aa = [0]
bb = [0]
for i in range(1,len(a)):
  aa.append(a[i] + aa[i-1])
for i in range(1,len(b)):
  bb.append(b[i] + bb[i-1])

ans = 0
for i in range(n+1):
    zan = k - aa[i]
    if zan <= 0:
        break
    bcnt = bisect.bisect(bb,zan)
    ans = max(ans,i+bcnt-1)

print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

numOfA,numOfB,target = map(int, input().split())

timetoreadA = list(map(int,input().split()))
timetoreadB = list(map(int,input().split()))

timetoreadAacc = list(itertools.accumulate(timetoreadA))

booknumonlyA = 0
totaltime = 0
for time in timetoreadAacc:
	if target < time:
		break
	booknumonlyA += 1
	totaltime = time

bookreadA = booknumonlyA
bookread = [bookreadA]

for posB in range(numOfB):
	bookreadB = posB + 1
	newtime = totaltime + timetoreadB[posB]
	if newtime <= target:
		bookread.append(bookreadA + bookreadB)
		totaltime = newtime
	else:
		while newtime > target and bookreadA > 0:
			bookreadA -= 1
			newtime = newtime - timetoreadA[bookreadA]

		if newtime <= target:
			bookread.append(bookreadA + bookreadB)

		totaltime = newtime

print(bookread)

Submission status: Wrong Answer

Solution code:
import itertools

numOfA,numOfB,target = map(int, input().split())

timetoreadA = list(map(int,input().split()))
timetoreadB = list(map(int,input().split()))

timetoreadAacc = list(itertools.accumulate(timetoreadA))

booknumonlyA = 0
totaltime = 0
for time in timetoreadAacc:
	if target < time:
		break
	booknumonlyA += 1
	totaltime = time

bookreadA = booknumonlyA
bookread = [bookreadA]

for posB in range(numOfB):
	bookreadB = posB + 1
	newtime = totaltime + timetoreadB[posB]
	if newtime <= target:
		bookread.append(bookreadA + bookreadB)
		totaltime = newtime
	else:
		while newtime > target and bookreadA > 0:
			bookreadA -= 1
			newtime = newtime - timetoreadA[bookreadA-1]

		if newtime <= target:
			bookread.append(bookreadA + bookreadB)

		totaltime = newtime

print(max(bookread))

Submission status: Wrong Answer

Solution code:
import itertools

numOfA,numOfB,target = map(int, input().split())

timetoreadA = list(map(int,input().split()))
timetoreadB = list(map(int,input().split()))

timetoreadAacc = list(itertools.accumulate(timetoreadA))
booknumifonlyA = 0
timeifonlyA = 0
for time in timetoreadAacc:
	if target < time:
		break
	booknumifonlyA += 1
	timeifonlyA = time

time = timeifonlyA
bookcanbereadatA = booknumifonlyA
bookcanberead = [bookcanbereadatA]

for bookcanbereadatB in range(numOfB):
	if newtime := time + timetoreadB[bookcanbereadatB] <= target:
		bookcanberead.append(bookcanbereadatA + bookcanbereadatB + 1)
		time = newtime
	else:
		while newtime > target and bookcanbereadatA > 1:
			bookcanbereadatA -= 1
			newtime = newtime - timetoreadA[bookcanbereadatA-1]
		time = newtime

print(max(bookcanberead))