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:
import numpy as np
import bisect
N,M,K= map(int, input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
if A[0]>K and B[0]>K:print(0);exit()

Asum=[0]
for i in range(N):
  if Asum[-1]+A[i]<=K:
    Asum.append(Asum[-1]+A[i])  

Bsum=[0]
for j in range(M):
  if Bsum[-1]+B[j]<=K:
    Bsum.append(Bsum[-1]+B[j])
AAsum=[]
for i in range(len(Asum)):
  AAsum.append(K-Asum[i])

#print(Asum)
#print(AAsum)
#print(Bsum)

C=[]
for i in range(len(Asum)):
  C.append(bisect.bisect(Bsum,K-Asum[i])+i-1)

#print(Asum)
#print(AAsum)
#print(Bsum)
#print(C)
print(max(C))

Submission status: Wrong Answer

Solution code:
import numpy as np
import bisect
N,M,K= map(int, input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
if A[0]>K and B[0]>K:print(0);exit()

Asum=[0]
for i in range(N):
    Asum.append(Asum[-1]+A[i])  

Bsum=[0]
for j in range(M):
    Bsum.append(Bsum[-1]+B[j])

AAsum=[]
for i in range(N):
  AAsum.append(K-Asum[i])

#print(Asum)
#print(AAsum)
#print(Bsum)

C=[]
for i in range(N):
  C.append(bisect.bisect(Bsum,K-Asum[i])+i-1)

#print(Asum)
#print(AAsum)
#print(Bsum)
#print(C)_
print(max(C))
#176882

Submission status: Wrong Answer

Solution code:
import numpy as np
import bisect
N,M,K= map(int, input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
if A[0]>K and B[0]>K:print(0);exit()

Asum=[0]
for i in range(N):
    Asum.append(Asum[-1]+A[i])  

Bsum=[0]
for j in range(M):
    Bsum.append(Bsum[-1]+B[j])

AAsum=[]
for i in range(N):
  AAsum.append(K-Asum[i])

#print(Asum)
#print(AAsum)
#print(Bsum)

C=[]
for i in range(len(Asum)):
  C.append(bisect.bisect(Bsum,K-Asum[i])+i-1)

#print(Asum)
#print(AAsum)
#print(Bsum)
#print(C)
print(max(C))

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

ac = 0
bc = 0
ans = 0
t = 0

while t<k:
  if bc<=m-1 and ac <=n-1:
    if a[ac] > b[bc]:
      t += b[bc]
      bc +=1

    else:
      t+= a[ac]
      ac+=1
 
  elif ac >= n and bc<=m-1:
    t += b[bc]
    bc +=1

  elif bc >= m and ac<=n-1:
    t+= a[ac]
    ac+=1
  else:
    print(ac+bc)
    exit()

ans = ac+bc
if t>k:
  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()))

ac = 0
bc = 0
ans = 0
t = 0

while t<k:
  if bc<=m-1 and ac <=n-1:
    if a[ac] > b[bc]:
      t += b[bc]
      bc +=1

    else:
      t+= a[ac]
      ac+=1
 
  elif ac >= n and bc<=m-1:
    t += b[bc]
    bc +=1

  elif bc >= m and ac<=n-1:
    t+= a[ac]
    ac+=1

ans = ac+bc
if t>k:
  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()))

ac = 0
bc = 0
ans = 0
t = 0

while t<k:
  if bc<=m-1 and ac <=n-1:
    if a[ac] > b[bc]:
      t += b[bc]
      bc +=1
      ans+=1
    else:
      t+= a[ac]
      ac+=1
      ans+=1
  elif ac >= n and bc<=m-1:
    t += b[bc]
    bc +=1
    ans+=1
  elif bc >= m and ac<=n-1:
    t+= a[ac]
    ac+=1
    ans +=1

if t>k:
  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()))

ac = 0
bc = 0
ans = 0
t = 0

while t<k:
  if bc<=m-1 and ac <=n-1:
    if a[ac] > b[bc]:
      t += b[bc]
      bc +=1
    else:
      t+= a[ac]
      ac+=1
      ans+=1
  elif ac >= n and bc<=m-1:
    t += b[bc]
    bc +=1
    ans+=1
  elif bc >= m and ac<=n-1:
    t+= a[ac]
    ac+=1
    ans +=1

if t>k:
  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()))

ac = 0
bc = 0
ans = 0
t = 0

while t<k:
  if bc<=m-1 and ac <=n-1:
    if a[ac] > b[bc]:
      t += b[bc]
      bc +=1
      ans+=1
    else:
      t+= a[ac]
      ac+=1
      ans+=1
  elif ac >= n and bc<=m-1:
    t += b[bc]
    bc +=1
    ans+=1
  elif bc >= m and ac<=n-1:
    t+= a[ac]
    ac+=1

if t>k:
  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()))

ac = 0
bc = 0
ans = 0
t = 0

while t<k:
  if bc<=m-1 and ac <=n-1:
    if a[ac] > b[bc]:
      t += b[bc]
      bc +=1
      ans+=1
    else:
      t+= a[ac]
      ac+=1
      ans+=1
  elif ac >= n and bc<=m-1:
    t += b[bc]
    bc +=1
    ans+=1
  elif bc == m and ac<=n-1:
    t+= a[ac]
    ac+=1

if t>k:
  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()))

ac = 0
bc = 0
ans = 0
t = 0

while t<=k:
  if bc<=m-1 and ac <=n-1:
    if a[ac] > b[bc]:
      t += b[bc]
      bc +=1
    else:
      t+= a[ac]
      ac+=1
  elif ac >= n and bc<=m-1:
    t += b[bc]
    bc +=1
  elif bc == m and ac<=n-1:
    t+= a[ac]
    ac+=1
  ans+=1

if t>k:
  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()))

ac = 0
bc = 0
ans = 0
t = 0
while t<=k:
  if bc<=m-1 and ac <=n-1:
    if a[ac] > b[bc]:
      t += b[bc]
      bc +=1
    else:
      t+= a[ac]
      ac+=1
  elif ac >= n and bc<=m-1:
    t += b[bc]
    bc +=1
    print(t)
  elif bc == m and ac<=n-1:
    t+= a[ac]
    ac+=1
  ans+=1

if t>k:
  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()))
c=[]
ac = 0
bc = 0
ans = 0
t = 0
while t<k:
  if bc<=m-1 and ac <=n-1:
    if a[ac] > b[bc]:
      t += b[bc]
      bc +=1
    else:
      t+= a[ac]
      ac+=1
  elif ac >= n and bc<=m-1:
    t += b[bc]
    bc +=1
    print(t)
  elif bc == m and ac<=n-1:
    t+= a[ac]
    ac+=1
  ans+=1

if t>k:
  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()))

ac = 0
bc = 0
ans = 0
t = 0
while t<k:
  if bc<=m-1 and ac <=n-1:
    if a[ac] > b[bc]:
      t += b[bc]
      bc +=1
    else:
      t+= a[ac]
      ac+=1
  elif ac >= n and bc<=m-1:
    t += b[bc]
    bc +=1
    print(t)
  elif bc == m and ac<=n-1:
    t+= a[ac]
    ac+=1
  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()))

ac = 0
bc = 0
ans = 0
t = 0
while t<k:
  if bc<=m-1 and ac <=n-1:
    if a[ac] > b[bc]:
      t += b[bc]
      bc +=1
    else:
      t+= a[ac]
      ac+=1
  elif ac >= n and bc<=m-1:
    t += b[bc]
    bc +=1
    print(t)
  elif bc == m and ac<=n-1:
    t+= a[ac]
    ac+=1
  else:
      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()))

ac = 0
bc = 0
ans = 0
t = 0
while t<k:
  if bc<=m-1 and ac <=n-1:
    if a[ac] > b[bc]:
      t += b[bc]
      bc +=1
    else:
      t+= a[ac]
      ac+=1
  elif ac == n:
    t += b[bc]
    bc +=1
    print(t)
  elif bc == m:
    t+= a[ac]
    ac+=1
  else:
      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()))

m = 0
n = 0
total = 0
ans =0
#行数分繰り返して配列取得
for i in range(len(A)+len(B)):
    if total == K:
        break
    elif total > K:
        ans = ans -1
        break
    if  n >= len(B):
       total += A[m]
       m += 1
    elif  m >= len(A):
        total += B[n]
        n += 1
    elif A[m] > B[n]:
        total += B[n]
        n += 1
    else:
        total += A[m]
        m += 1
    ans = m+n
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N,M,K= map(int, input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
#A = [int(i) for i in input().split()]
#B = [int(i) for i in input().split()]

if A[0]>K and B[0]>K:
  print(0);exit()
  
Asum=[0]*(N+1)
sum=0;i=0
Asum[0]=0
while sum<K and i+1<=N:
  sum+=A[i]
  if sum<K:Asum[i+1]=A[i]+Asum[i]
  i+=1
Amax=i-1

Bsum=[0]*(M+1)
sum=0;i=0
Bsum[0]=0
while sum<K and i+1<=M:
  sum+=B[i]
  if sum<K:Bsum[i+1]=B[i]+Bsum[i]  
  i+=1
Bmax=i-1

Max=0;X=0;Y=0
#print(Amax,N,Bmax,M,K)
for i in range(Amax,N+1):
  for j in range(1,M+1):
    if Asum[i]!=0 and Bsum[j]!=0 and Max<=Asum[i]+Bsum[j] and Asum[i]+Bsum[j]<=K:
      Max=Asum[i]+Bsum[j]
      X=i;Y=j
    else:continue
Max=0;XX=0;YY=0
for i in range(1,N+1):
  for j in range(Bmax,M+1):
    if Asum[i]!=0 and Bsum[j]!=0 and Max<=Asum[i]+Bsum[j] and Asum[i]+Bsum[j]<=K:
      Max=Asum[i]+Bsum[j]
      XX=i;YY=j
    else:continue

#    else:Csum[i*(Bmax+1)+j]=Asum[i]+Bsum[j]
#print(Max)
#print(Asum[X],X,Bsum[Y],Y)
#print(Asum[XX],XX,Bsum[YY],YY)

print(max(X+Y,XX+YY))

Submission status: Wrong Answer

Solution code:
import numpy as np
N,M,K= map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
if A[0]>K and B[0]>K:
  print(0);exit()
  
Asum=[0]*(N+1)
sum=0;i=0
Asum[0]=0
while sum<K and i+1<=N:
  sum+=A[i]
  if sum<K:Asum[i+1]=A[i]+Asum[i]
  i+=1
Amax=i-1

Bsum=[0]*(M+1)
sum=0;i=0
Bsum[0]=0
while sum<K and i+1<=M:
  sum+=B[i]
  if sum<K:Bsum[i+1]=B[i]+Bsum[i]  
  i+=1
Bmax=i-1

Max=0;X=0;Y=0
#print(Amax,N,Bmax,M,K)
for i in range(Amax,N+1):
  for j in range(1,M+1):
    if Asum[i]!=0 and Bsum[j]!=0 and Max<=Asum[i]+Bsum[j] and Asum[i]+Bsum[j]<=K:
      Max=Asum[i]+Bsum[j]
      X=i;Y=j
    else:continue
Max=0;XX=0;YY=0
for i in range(1,N+1):
  for j in range(Bmax,M+1):
    if Asum[i]!=0 and Bsum[j]!=0 and Max<=Asum[i]+Bsum[j] and Asum[i]+Bsum[j]<=K:
      Max=Asum[i]+Bsum[j]
      XX=i;YY=j
    else:continue

#    else:Csum[i*(Bmax+1)+j]=Asum[i]+Bsum[j]
#print(Max)
#print(Asum[X],X,Bsum[Y],Y)
#print(Asum[XX],XX,Bsum[YY],YY)

print(max(X+Y,XX+YY))

Submission status: Wrong Answer

Solution code:
import numpy as np
N,M,K= map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

Asum=[0]*(N+1)
sum=0;i=0
Asum[0]=0
while sum<K and i+1<=N:
  sum+=A[i]
  if sum<K:Asum[i+1]=A[i]+Asum[i]
  i+=1
Amax=i-1

Bsum=[0]*(M+1)
sum=0;i=0
Bsum[0]=0
while sum<K and i+1<=M:
  sum+=B[i]
  if sum<K:Bsum[i+1]=B[i]+Bsum[i]  
  i+=1
Bmax=i-1

Max=0;X=0;Y=0
#print(Amax,N,Bmax,M,K)
for i in range(Amax,N+1):
  for j in range(1,M+1):
    if Asum[i]!=0 and Bsum[j]!=0 and Max<=Asum[i]+Bsum[j] and Asum[i]+Bsum[j]<=K:
      Max=Asum[i]+Bsum[j]
      X=i;Y=j
    else:continue
Max=0;XX=0;YY=0
for i in range(1,N+1):
  for j in range(Bmax,M+1):
    if Asum[i]!=0 and Bsum[j]!=0 and Max<=Asum[i]+Bsum[j] and Asum[i]+Bsum[j]<=K:
      Max=Asum[i]+Bsum[j]
      XX=i;YY=j
    else:continue

#    else:Csum[i*(Bmax+1)+j]=Asum[i]+Bsum[j]
#print(Max)
#print(Asum[X],X,Bsum[Y],Y)
#print(Asum[XX],XX,Bsum[YY],YY)
if A[0]>K and B[0]>K:
  print(0);exit()
print(max(X+Y,XX+YY))

Submission status: Wrong Answer

Solution code:
import numpy as np
N,M,K= map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

Asum=[0]*(N+1)
sum=0;i=0
Asum[0]=0
while sum<K and i+1<=N:
  sum+=A[i]
  if sum<K:Asum[i+1]=A[i]+Asum[i]
  i+=1
Amax=i-1

Bsum=[0]*(M+1)
sum=0;i=0
Bsum[0]=0
while sum<K and i+1<=M:
  sum+=B[i]
  if sum<K:Bsum[i+1]=B[i]+Bsum[i]  
  i+=1
Bmax=i-1

Max=0;X=0;Y=0
#print(Amax,N,Bmax,M,K)
for i in range(Amax,N+1):
  for j in range(1,M+1):
    if Asum[i]!=0 and Max<=Asum[i]+Bsum[j] and Asum[i]+Bsum[j]<=K:
      Max=Asum[i]+Bsum[j]
      X=i;Y=j
    else:continue
Max=0;XX=0;YY=0
for i in range(1,N+1):
  for j in range(Bmax,M+1):
    if Bsum[j]!=0 and Max<=Asum[i]+Bsum[j] and Asum[i]+Bsum[j]<=K:
      Max=Asum[i]+Bsum[j]
      XX=i;YY=j
    else:continue

#    else:Csum[i*(Bmax+1)+j]=Asum[i]+Bsum[j]
#print(Max)
#print(Asum[X],X,Bsum[Y],Y)
#print(Asum[XX],XX,Bsum[YY],YY)
if A[0]>K and B[0]>K:
  print(0);exit()
print(max(X+Y,XX+YY))

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = [int(v) for v in input().split()]
b = [int(v) for v in input().split()]
ans = []
for _ in range(n + m):
    if len(a) > 0 and len(b) > 0 and a[0] <= b[0] and a[0] <= k:
        k -= a[0]
        ans.append(a[0])
        a.pop(0)
    elif len(a) > 0 and len(b) > 0 and b[0] <= a[0] and b[0] <= k:
        k -= b[0]
        ans.append(b[0])
        b.pop(0)
    elif len(a) == 0 and len(b) > 0 and b[0] <= k:
        k -= b[0]
        ans.append(b[0])
        b.pop(0)
    elif len(b) == 0 and len(a) > 0 and a[0] <= k:
        k -= a[0]
        ans.append(a[0])
        a.pop(0)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = [int(v) for v in input().split()]
b = [int(v) for v in input().split()]
ans = []
for i in range(n + m):
    if i < len(a) and a[i] <= k:
        ans.append(a[i])
        k -= a[i]
    if i < len(b) and b[i] <= k:
        ans.append(b[i])
        k -= b[i]
print(len(ans))

Submission status: Wrong Answer

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

    total_T_in_A = [0] * (N+1)
    total_T_in_B = [0] * M

    for i in range(1, N+1):
        total_T_in_A[i] = total_T_in_A[i-1] + A[i-1]

    for i in range(1, M):
        total_T_in_B[i] = total_T_in_B[i-1] + B[i]

    result = 0
    for i in range(N+1):
        # A から i 冊読むときにかかる時間
        i_A_T = total_T_in_A[i]
        
        if K < i_A_T:
            continue

        if K == i_A_T:
            result = max(result, i)
            continue

        rem_T = K - i_A_T

        # total_T_in_B は累積和を格納した、ソート済の配列
        # B_i <= rem_T < B_i+1 となるような B_i を二分探索によって探す
        first = total_T_in_B[0]
        last = total_T_in_B[M-1]
        if rem_T < first:
            result = max(result, i)
            continue
        if last <= rem_T:
            result = max(result, i + M)
            continue

        # assume that first <= rem_T <= last
        first_i = 0
        last_i = M - 1
        while first_i < last_i:
            if abs(last_i - first_i) == 1:
                break
            mid_i = (first_i + last_i) // 2
            if rem_T < total_T_in_B[mid_i]:
                last_i = mid_i
            else:
                first_i = mid_i
        result = max(result, i + first_i + 1)

    print(result)

main()

Submission status: Wrong Answer

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

    total_T_in_A = [0] * N
    total_T_in_A[0] = A[0]
    total_T_in_B = [0] * M
    total_T_in_B[0] = B[0]

    for i in range(1, N):
        total_T_in_A[i] = total_T_in_A[i-1] + A[i]

    for i in range(1, M):
        total_T_in_B[i] = total_T_in_B[i-1] + B[i]

    result = 0
    for i in range(N):
        # A から i+1 冊読むときにかかる時間
        i_A_T = total_T_in_A[i]
        
        if K < i_A_T:
            continue

        if K == i_A_T:
            result = max(result, i + 1)
            continue

        rem_T = K - i_A_T

        # total_T_in_B は累積和を格納した、ソート済の配列
        # B_i <= rem_T < B_i+1 となるような B_i を二分探索によって探す
        first = total_T_in_B[0]
        last = total_T_in_B[M-1]
        if rem_T < first:
            result = max(result, i + 1)
            continue
        if last <= rem_T:
            result = max(result, i + 1 + M)
            continue

        # assume that first <= rem_T <= last
        first_i = 0
        last_i = M - 1
        while first_i < last_i:
            if abs(last_i - first_i) == 1:
                break
            mid_i = (first_i + last_i) // 2
            if rem_T < total_T_in_B[mid_i]:
                last_i = mid_i
            else:
                first_i = mid_i
        result = max(result, i + 1 + first_i + 1)

    print(result)

main()

Submission status: Wrong Answer

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

    total_T_in_A = [0] * N
    total_T_in_A[0] = A[0]
    total_T_in_B = [0] * M
    total_T_in_B[0] = B[0]

    for i in range(1, N):
        total_T_in_A[i] = total_T_in_A[i-1] + A[i]

    for i in range(1, M):
        total_T_in_B[i] = total_T_in_B[i-1] + B[i]

    result = 0
    for i in range(N):
        # A から i+1 冊読むときにかかる時間
        i_A_T = total_T_in_A[i]
        
        if K < i_A_T:
            continue

        if K == i_A_T:
            result = max(result, i)
            continue

        rem_T = K - i_A_T

        # total_T_in_B は累積和を格納した、ソート済の配列
        # B_i <= rem_T < B_i+1 となるような B_i を二分探索によって探す
        first = total_T_in_B[0]
        last = total_T_in_B[M-1]
        if rem_T < first:
            continue
        if last <= rem_T:
            result = max(result, i + 1 + M)
            continue

        # assume that first <= rem_T <= last
        first_i = 0
        last_i = M - 1
        while first_i < last_i:
            if abs(last_i - first_i) == 1:
                break
            mid_i = (first_i + last_i) // 2
            if rem_T < total_T_in_B[mid_i]:
                last_i = mid_i
            else:
                first_i = mid_i
        result = max(result, i + 1 + first_i + 1)

    print(result)

main()

Submission status: Wrong Answer

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

    total_T_in_A = [0] * N
    total_T_in_A[0] = A[0]
    total_T_in_B = [0] * M
    total_T_in_B[0] = B[0]

    for i in range(1, N):
        total_T_in_A[i] = total_T_in_A[i-1] + A[i]

    for i in range(1, M):
        total_T_in_B[i] = total_T_in_B[i-1] + B[i]

    total = total_T_in_A[N-1] + total_T_in_B[M-1]

    if total <= K:
        print(N + M)
        return

    result = N + M
    A_i = N-1
    B_i = M-1

    while total > K:
        if A_i < 0 and B_i < 0:
            break
        elif A_i >= 0 and B_i < 0:
            total -= A[A_i]
            A_i -= 1
        elif A_i < 0 and B_i >= 0:
            total -= B[B_i]
            B_i -= 1
        else:
            lastA = total_T_in_A[A_i]
            lastB = total_T_in_B[B_i]
            if lastA > lastB:
                total -= A[A_i]
                A_i -= 1
            else:
                total -= B[B_i]
                B_i -= 1
        result -= 1

    print(result)

main()

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc172/tasks/abc172_c

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


curr_A = 0
curr_B = 0
total_t = 0
count_r = 0

len_A = len(A_list)
len_B = len(B_list)

while curr_A < len_A or curr_B < len_B:
    if curr_A >= len_A:
        total_t += B_list[curr_B]
        curr_B += 1
    
    elif curr_B >= len_B:
        total_t += A_list[curr_A]
        curr_A += 1

    elif A_list[curr_A] <= B_list[curr_B]:
        total_t += A_list[curr_A]
        curr_A += 1
    
    else:
        total_t += B_list[curr_B]
        curr_B += 1

    count_r += 1
    
    if total_t > K:
        count_r -= 1
        break


print(count_r)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
time = 0
num_A = 0

for i in range(N):
    if time + A[i] >= K:
        break
    else:
        time += A[i]
        num_A += 1
#print(num_A)
ans = num_A

i = 0
while i < M:
    while i < M and time + B[i] <= K:
        time += B[i]
        i += 1
    ans = max(num_A+i, ans)
    if i == M-1:
        break
    elif num_A > 0:
        num_A -= 1
        time -= A[num_A]
    else:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
time = 0
num_A = 0

for i in range(N):
    if time + A[i] >= K:
        break
    else:
        time += A[i]
        num_A += 1

ans = num_A

i = 0
while i < M:
    while i < M and time + B[i] <= K:
        time += B[i]
        i += 1
    ans = max(num_A+i, ans)
    if num_A > 0:
        num_A -= 1
        time -= A[num_A]
    else:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
import numpy as np
def main():
    n, m, k = map(int, input().split())
    a = np.array(readline().split(), np.int64)
    b = np.array(readline().split(), np.int64)
    aa = a.cumsum()
    ba = b.cumsum()
    r = np.searchsorted(ba, k)
    aaa = k - aa
    for i1, aaae in enumerate(aaa):
        if aaae <= 0:
            break
        r = max(r, np.searchsorted(ba, aaae,side='right') + i1 + 1)
    print(r)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
import numpy as np
def main():
    n, m, k = map(int, input().split())
    a = np.array(readline().split(), np.int64)
    b = np.array(readline().split(), np.int64)
    aa = a.cumsum()
    ba = b.cumsum()
    r = np.searchsorted(ba, k)
    aaa = k - aa
    for i1, aaae in enumerate(aaa):
        if aaae > 0:
            r = max(r, np.searchsorted(ba, aaae) + i1 + 2)
    print(r)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
import numpy as np
def main():
    n, m, k = map(int, input().split())
    a = np.array(read().split(), np.int64)
    b = np.array(read().split(), np.int64)
    aa = a.cumsum()
    ba = b.cumsum()
    r = np.searchsorted(ba, k)
    aaa = k - aa
    for i1, aaae in enumerate(aaa):
        if aaae > 0:
            r = max(r, np.searchsorted(ba, aaae) + i1 + 2)
    print(r)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
import numpy as np
def main():
    n, m, k = map(int, input().split())
    a = np.array(read().split(), np.int64)
    b = np.array(read().split(), np.int64)
    aa = a.cumsum()
    ba = b.cumsum()
    r = np.searchsorted(ba, k)
    aaa = k - aa
    for i1, aaae in enumerate(aaa):
        if aaae > 0:
            r = max(r, np.searchsorted(ba, aaae)) + i1 + 1
    print(r)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

    total_T_in_A = [0] * N
    total_T_in_A[0] = A[0]
    total_T_in_B = [0] * M
    total_T_in_B[0] = B[0]

    for i in range(1, N):
        total_T_in_A[i] = total_T_in_A[i-1] + A[i]

    for i in range(1, M):
        total_T_in_B[i] = total_T_in_B[i-1] + B[i]

    total_A = total_T_in_A[N-1]
    total_B = total_T_in_B[M-1]
    total = total_A + total_B

    if total <= K:
        print(N + M)
        return

    result = N + M
    A_i = N-1
    B_i = M-1

    while total > K:
        if A_i < 0 and B_i < 0:
            print(0)
            return
        elif A_i >= 0 and B_i < 0:
            total -= A[A_i]
            A_i -= 1
        elif A_i < 0 and B_i >= 0:
            total -= B[B_i]
            B_i -= 1
        else:
            lastA = total_T_in_A[A_i]
            lastB = total_T_in_B[B_i]
            if lastA > lastB:
                total -= A[A_i]
                A_i -= 1
            else:
                total -= B[B_i]
                B_i -= 1
        result -= 1

    print(result)

main()

Submission status: Wrong Answer

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

    total_T_in_A = [0] * N
    total_T_in_A[0] = A[0]
    total_T_in_B = [0] * M
    total_T_in_B[0] = B[0]

    for i in range(1, N):
        total_T_in_A[i] = total_T_in_A[i-1] + A[i]

    for i in range(1, M):
        total_T_in_B[i] = total_T_in_B[i-1] + B[i]

    print(total_T_in_A)
    print(total_T_in_B)

    total_A = total_T_in_A[N-1]
    total_B = total_T_in_B[M-1]
    total = total_A + total_B

    if total <= K:
        print(N + M)
        return

    result = N + M
    A_i = N-1
    B_i = M-1

    while total > K:
        if A_i < 0 and B_i < 0:
            print(0)
            return
        elif A_i >= 0 and B_i < 0:
            total -= A[A_i]
            A_i -= 1
        elif A_i < 0 and B_i >= 0:
            total -= B[B_i]
            B_i -= 1
        else:
            lastA = total_T_in_A[A_i]
            lastB = total_T_in_B[B_i]
            if lastA > lastB:
                total -= A[A_i]
                A_i -= 1
            else:
                total -= B[B_i]
                B_i -= 1
        result -= 1

    print(result)

main()

Submission status: Wrong Answer

Solution code:
def judge(n,array1,array2,K):
    for i in range(n):
        if len(array1) > i and len(array2) > n-i:
            sum = array1[i] + array2[n-i]
            if sum <= K:
                return True
    return False

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

cum_sum_As = [0]
cum_sum_Bs = [0]

sum_As = 0
for i in range(N):
    sum_As += As[i]
    cum_sum_As.append(sum_As)

sum_Bs = 0
for i in range(M):
    sum_Bs += Bs[i]
    cum_sum_Bs.append(sum_Bs)


l = 0
r = N + M
while(r-l>1):
    mid = (l+r)//2
    if judge(mid,cum_sum_As,cum_sum_Bs,K):
        l = mid
    else:
        r = mid
if judge(r+1,cum_sum_As,cum_sum_Bs,K):
    print(r+1)
elif judge(r,cum_sum_As,cum_sum_Bs,K):
    print(r)
else:
    print(l)

Submission status: Wrong Answer

Solution code:
def judge(n,array1,array2,K):
    for i in range(n):
        if len(array1) > i and len(array2) > n-i:
            sum = array1[i] + array2[n-i]
            if sum <= K:
                return True
    return False

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

cum_sum_As = [0]
cum_sum_Bs = [0]

sum_As = 0
for i in range(N):
    sum_As += As[i]
    cum_sum_As.append(sum_As)

sum_Bs = 0
for i in range(M):
    sum_Bs += Bs[i]
    cum_sum_Bs.append(sum_Bs)

l = 0
r = N + M
while(r-l>1):
    mid = (l+r)//2
    if judge(mid,cum_sum_As,cum_sum_Bs,K):
        l = mid
    else:
        r = mid

if judge(r,cum_sum_As,cum_sum_Bs,K):
    print(r)
else:
    print(l)

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()))
cost = 0
num = 0
i = 0
j = 0
while True:

    if i==len(a) and j==len(b):
        break
    elif i==len(a):
        cost += b[j]
        j += 1
    elif j==len(b):
        cost += a[i]
        i += 1

    elif a[i]<=b[j]:
        cost += a[i]
        i += 1
    elif a[i]>b[j]:
        cost += b[j]
        j += 1
    if cost>k:
        break
    num += 1

print(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()))
cost = 0
num = 0
i = 0
j = 0
while True:

    if i==len(a) and j==len(b):
        break
    elif i>(len(a)-1):
        cost += b[j]
        j += 1
    elif j>(len(b)-1):
        cost += a[i]
        i += 1

    elif a[i]<=b[j]:
        cost += a[i]
        i += 1
    elif a[i]>b[j]:
        cost += b[j]
        j += 1
    if cost>k:
        break
    num += 1

print(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()))
cost = 0
num = 0
i = 0
j = 0
while True:

    if i==len(a) and j==len(b):
        break
    elif i>(len(a)-1):
        cost += b[j]
        j += 1
    elif j>(len(b)-1):
        cost += a[i]
        i += 1

    elif a[i]<=b[j]:
        cost += a[i]
        i += 1
    elif a[i]>=b[j]:
        cost += b[j]
        j += 1
    if cost>k:
        break
    num += 1

print(num)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    N, M, K = map(int, input().split()) 
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    
    acc_A = []
    acc_B = []
    acc_A.append(0)
    acc_B.append(0)
    
    sum_a = 0
    sum_b = 0

    for a in A:
        sum_a += a
        acc_A.append(sum_a)

    for b in B:
        sum_b += b
        acc_B.append(sum_b)

    large_ar = []
    small_ar = []

    if N > M:
        large_ar = acc_A
        small_ar = acc_B
    else:
        large_ar = acc_B
        small_ar = acc_A
    
    ans = 0
    for i in range(len(small_ar)):
        for j in range(ans-i-1, len(large_ar)):
            if large_ar[j] + small_ar[i] <= K:
                ans = max(ans, i+j)
            else: break
    print(ans)