Problem: 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.

Submission attempts (in order):
# -*- coding: utf-8 -*-

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

Nmax=len(Nnums)
Mmax=len(Mnums)
Nsum=0
Ncnt=0


for Ni,Nl in enumerate(Nnums):
  Nsum += Nl
  Ncnt = Ni
  if Nsum > K:
    Nsum -= Nl
    Ncnt = Ni-1
    break
    
chkSum = Nsum
chkCnt = Ncnt + 1
AnsCnt = Ncnt + 1


for Mi,Ml in enumerate(Mnums):
  chkSum += Ml
  chkCnt += 1
  if (chkSum > K):
    flg = 0
    while chkSum > K:
      if Ncnt >= 0:
        chkSum -= Nnums[Ncnt]
        chkCnt -= 1
        Ncnt -= 1
        flg = 1
      else:
        if flg == 0:
          
          chkCnt -= 1
          AnsCnt -= 1
        break
  
  if (AnsCnt < chkCnt):
    AnsCnt = chkCnt
  
#  if (Ncnt < 0):
  if (chkSum > K):
    break
    
print(AnsCnt)

# -*- coding: utf-8 -*-

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

Nmax=len(Nnums)
Mmax=len(Mnums)
Nsum=0
Ncnt=0


for Ni,Nl in enumerate(Nnums):
  Nsum += Nl
  Ncnt = Ni
  if Nsum > K:
    Nsum -= Nl
    Ncnt = Ni-1
    break
    
chkSum = Nsum
chkCnt = Ncnt + 1
AnsCnt = Ncnt + 1
  

for Mi,Ml in enumerate(Mnums):
  chkSum += Ml
  chkCnt += 1
  if (chkSum > K):
    if 
    while chkSum > K:
      if not Ncnt < 0:
        chkSum -= Nnums[Ncnt]
        chkCnt -= 1
        Ncnt -= 1
      elif:
        break
  
  if (AnsCnt < chkCnt):
    AnsCnt = chkCnt
  
  if (Ncnt < 0):
    break

print(AnsCnt)


# -*- coding: utf-8 -*-

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

Nmax=len(Nnums)
Mmax=len(Mnums)
Nsum=0
Ncnt=0


for Ni,Nl in enumerate(Nnums):
  Nsum += Nl
  Ncnt = Ni
  if Nsum > K:
    Nsum -= Nl
    Ncnt = Ni-1
    break
    
chkSum = Nsum
chkCnt = Ncnt + 1
AnsCnt = Ncnt + 1


for Mi,Ml in enumerate(Mnums):
  chkSum += Ml
  chkCnt += 1
  if (chkSum > K):
    while chkSum > K:
      if Ncnt >= 0:
        chkSum -= Nnums[Ncnt]
        chkCnt -= 1
        Ncnt -= 1
      else:
        
        chkCnt -= 1
        AnsCnt -= 1
        break
  
  if (AnsCnt < chkCnt):
    AnsCnt = chkCnt
  
#  if (Ncnt < 0):
  if (chkSum > K):
    break
    
print(AnsCnt)

# -*- coding: utf-8 -*-

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

Nmax=len(Nnums)
Mmax=len(Mnums)
Nsum=0
Ncnt=0


for Ni,Nl in enumerate(Nnums):
  Nsum += Nl
  Ncnt = Ni
  if Nsum > K:
    Nsum -= Nl
    Ncnt = Ni-1
    break
    
chkSum = Nsum
chkCnt = Ncnt + 1
AnsCnt = Ncnt + 1


for Mi,Ml in enumerate(Mnums):
  chkSum += Ml
  chkCnt += 1
  if (chkSum > K):
    flg = 0
    while chkSum > K:
      if Ncnt >= 0:
        chkSum -= Nnums[Ncnt]
        chkCnt -= 1
        Ncnt -= 1
        flg = 1
      else:
        if flg == 0:
          
          chkCnt -= 1
          #AnsCnt -= 1
        break
  
  if (AnsCnt < chkCnt):
    AnsCnt = chkCnt
  

  
#  if (Ncnt < 0):
  if (chkSum > K):
    break
    
print(AnsCnt)

Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Accepted