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()))
c=0
count=0
while c+min(a[0],b[0])<=k:
  
 c+=min(a[0],b[0])
 count+=1
 if min(a[0],b[0])==a[0]:
   a.remove(a[0])
   if not a:
        a.append(1000000000)
 else:
   b.remove(b[0]) 
   if not b:
        b.append(1000000000)
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()))

time=0
ans=0
count=0
for i in range(N):
  if(time+A[i]<=K):
    time+=A[i]
    count+=1
  else:
    break
ans=count
btime=0
bcount=0
for i in range(M):
  if(btime+B[i]<=K):
    btime+=B[i]
    bcount+=1
  else:
    break
a=0
b=0
time+=btime
if(count+bcount==0):
  print(0)
  exit()
if(count==N and bcount==M):
  print(N+M)
  exit()
for i in range(count+bcount):
  if(A[count-1-a]<=B[bcount-1-b]):
    time-=B[bcount-1-b]
    b+=1
  else:
    time-=A[count-1-a]
    a+=1
  if(time<=K):
    print(count+bcount-a-b)
    exit()

Submission status: Wrong Answer

Solution code:
#import collections
# c = collections.Counter()
#import itertools as it
#import math
#import numpy as np
import sys 
#sys.exit()
 
#s = input()
#t = input()
 
#k = int(input())
#a, b  = map(int, input().split())
'''
#  = list(map(int, input().split()))
'''
'''
n = input()
a = [int(input()) for i in range(n)]
'''
#a = [list(map(int, input().split())) for _ in range(n)]
n,m,k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

#-------------------------------#
#len(t)==len(s)+1
#print(t[0:-1])
'''
count=0
for i in range (len(s)):
    if s[i]!=t[i]:
        count=count+1
'''
c=a+b
d=sorted(c)
count=0
savesum=0
for i in range (len(d)):
    #savesum=sum(d[0:i+1])
    savesum=savesum+d[i]
    if savesum<=k:
        count=count+1
print(count)

Submission status: Wrong Answer

Solution code:
import math

n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
pre = 0
ai = -1
for i in range(n):
  pre += a[i]
  a[i] = pre
  if pre <= k:
    ai = i
pre = 0
bi = -1
for i in range(m):
  pre += b[i]
  b[i] = pre
  if pre <= k:
    bi = i
while a[ai] + b[bi] > k:
  if ai < 0 or bi < 0:
    break
  l = math.ceil(a[ai]/(ai+1))
  r = math.ceil(b[bi]/(bi+1))
  if l == r:
    if ai == n-1:
      bi -= 1
    elif bi == m-1:
      ai -= 1
    elif abs(a[ai]-a[ai+1]) >= abs(b[bi]-b[bi+1]):
      ai -= 1
    else:
      bi -= 1
  elif l < r:
    bi -= 1
  else:
    ai -= 1
print(ai+bi+2)

Submission status: Wrong Answer

Solution code:
N,M,K = (int(x) for x in input().split())
A = list(map(int, input().strip().split()))
B = list(map(int, input().strip().split()))
book = [[-1 for _ in range(N+1)] for _ in range(M+1)]
book[0][0] = 0
ans = -1
numa = len(A)
numb = len(B)
for i in range(len(A)):
    book[0][i+1] = book[0][i] + A[i]
    if K < book[0][i+1]:
        ans = i
        numa = i
        break
if ans == -1:
  ans = len(A)
for i in range(len(B)):
    book[i+1][0] = book[i][0] + B[i]
    if K < book[i+1][0]:
        if ans < i:
            ans = i
        numb = i
        break
for i in range(numb):
    book[i+1][numa] = book[i][numa] + B[i]
    if K >= book[i+1][numa]:
        ans += 1
        continue
    for j in range(numa,-1,-1):
        book[i+1][j] = book[0][j] + book[i+1][0]
        if K >= book[i+1][j]:
            numa = j
            if ans < i + j + 1:
                ans = i + j + 1
            break
        if j == 0:
            numa = 0
print(ans)

Submission status: Wrong Answer

Solution code:
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools


#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]


N, M, K = map(int, input().split())
dp = [[]]
#A = deque([int(i) for i in input().split()])
#B = deque([int(i) for i in input().split()])
A = [int(i) for i in input().split()]
AA = [0]
B = [int(i) for i in input().split()]
BB = [0]
for i in range(1,N+1):
    AA.append(AA[i-1]+A[i-1])
for i in range(1,M+1):
    BB.append(BB[i-1]+B[i-1])
ans = []
A_idx = 0
B_idx = M

for i in range(N+M):
    if(K<=AA[A_idx]+BB[B_idx]):
        if(B_idx>0):
            B_idx -= 1
        if(K>=AA[A_idx]+BB[B_idx]):
            ans.append(A_idx + B_idx)
    elif(K>=AA[A_idx]+BB[B_idx]):
        if(A_idx<N):
            A_idx += 1
        if(K>=AA[A_idx]+BB[B_idx]):
            ans.append(A_idx + B_idx)


print(max(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()))
ans = 0
a_now = 0
b_now = 0

while True:
    ans_time = 0
    if len(A) <= a_now and len(B) <= b_now:
        break
    elif len(A) <= a_now:
        ans_time += B[b_now]
        b_now += 1
    elif len(B) <= b_now:
        ans_time += A[a_now]
        a_now += 1
    else:
        if A[a_now] >= B[b_now]:
            ans_time += B[b_now]
            b_now += 1
        else:
            ans_time += A[a_now]
            a_now += 1

    if K >= ans_time:
        ans += 1
        ##print(K, ans_time, sep= " ")
        K -= ans_time
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
import itertools
N,M,K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
k = 0
for i in range(M):
    index = bisect.bisect_left(A,B[i],k+1)
    A.insert(index, B[i])
    k = index

z = list(itertools.accumulate(A))
if K>= z[-1]:
    print(N+M)
else:
    index = bisect.bisect_left(z, K)
    print(index)

Submission status: Wrong Answer

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

time = 0
books = 0
for i in range(N+M):
    if not A:
        for b in range(len(B)):
            if not B:
                break
            elif (time + B[0]) > K:
                break
            else:
                time += B.pop(0)
                books += 1

    elif not B:
        for a in range(len(A)):
            if not A:
                break
            elif (time + A[0]) > K:
                break
            else:
                time += A.pop(0)
                books += 1

    elif (time + min(A[0], B[0])) > K:
        break

    else:
        if A[0] < B[0]:
            time += A.pop(0)
            books += 1
        else:
            time += B.pop(0)
            books += 1

print(books)

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

maxcount = N + M


sum_money = []

for i in range(maxcount):
    if sum(sum_money) > K:
        break
    else:
        if not A:
            sum_money.append(B[0])
            B.pop(0)
        elif not B:
            sum_money.append(A[0])
            A.pop(0)
        else:
            if  A[0] > B[0]:
                sum_money.append(B[0])
                B.pop(0)

            elif A[0] < B[0]:
                sum_money.append(A[0])
                A.pop(0)

if not A and not B:
    print(len(sum_money))
elif len(sum_money) == 0:
    print(0)
else:
    print(len(sum_money) - 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()))

A_sum = 0
A_max = 0
B_sum = 0
B_max = 0
best_num = 0
A_max = N
flag = True # Aだけ読んで時間が尽きるかどうか

# Aを最大まで読んだ時の冊数と時間
for i in range(N):
    A_sum += A[i]
    if A_sum > K:
        A_sum -= A[i]
        A_max = i
        flag = False
        break
A = A[0:A_max]
now_num = A_max # 今の読んだ数
mixsum = A_sum # A,Bを合わせた時間
b_num = 0 # bを読んだ数
if flag:
    now_num += M
    b_num = M
    for i in range(M):
        mixsum += B[i]
        if mixsum > K:
            mixsum -= B[i]
            now_num += i
            b_num = i  #i冊読んだので次取るならi番目から
            break
A.reverse()
best_num = now_num
for i in range(A_max):
    mixsum -= A[i]
    now_num -= 1
    for j in range(b_num, M):
        mixsum += B[j]
        now_num += 1
        if mixsum > K:
            mixsum -= B[j]
            now_num -= 1
            break
    if now_num > best_num:
        best_num = now_num
print(best_num)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
A = [int(p) for p in input().split()]
B = [int(p) for p in input().split()]
Af = False
Bf = False
count = 0

for _ in range(n+m):
  if k<=0:
    break
  if Af and Bf:
    break
  if A[0] > k and B[0] > k:
    break
  if Af:
    k -= B.pop(0)
    count += 1
    if len(B)==0:
      B.append((10**9)+1)
      Bf = True
    continue
  if Bf:
    k -= A.pop(0)
    count += 1
    if len(A)==0:
      A.append((10**9)+1)
      Af = True
    continue
  if A[0] < B[0]:
    k -= A.pop(0)
    count += 1
    if len(A)==0:
      A.append((10**9)+1)
      Af = True
  else:
    k -= B.pop(0)
    count += 1
    if len(B)==0:
      B.append((10**9)+1)
      Bf = True
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()))
t = 0
n = 0
a = 0
b = 0
 
while K > t :
    if a < N and b < M :
        if A[a] < B[b] :
            t += A[a]
            n += 1
            a += 1
            if K < t :
                n -=1
                break
 
        elif A[a] > B[b] :
            t +=B[b]
            n += 1
            b += 1
            if K < t :
                n -=1
                break
        else :
            if sum(A) <= sum(B) :
                t += A[a]
                n += 1
                a += 1
                if K < t :
                    n -=1
                    break
            
            else :
                t +=B[b]
                n += 1
                b += 1
                if K < t :
                    n -=1
                    break
    elif a == N :
        while b < M :
            t += B[b]
            n += 1
            b += 1
            if K < t :
                n -=1
                break
        
        else :
            break
 
    else :
        while a < N :
            t += A[a]
            n += 1
            a += 1
            if K < t :
                n -=1
                break
 
print(n)

Submission status: Wrong Answer

Solution code:
#n=int(input())
#s=input()
#a = list(map(int,input().split()))
#q=int(input())
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
#bc = [list(map(int, input().split())) for i in range(q)]
i_a = len(a) -1
rwa = 0
# aだけの場合のMAX冊数
for i,e in enumerate(a):
    rwa += e
    if rwa > k:
        rwa -= e
        i_a = i - 1
        break

rwb = k - rwa
i_b = 0
mx = i_a + 1
for j,e in enumerate(b):
    if rwb >= e:
        i_b += 1
        mx = max(mx,i_a + 1 + i_b)
        rwb -= e
        continue
    else:
        while True:
            if i_a < 0 :
                break
            rwb += a[i_a]
            i_a -= 1
            if rwb >= e:
                break
        if i_a < 0:
            break

print(mx)

Submission status: Wrong Answer

Solution code:


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

A = [i for i in map(int, input().split())]
B = [i for i in map(int, input().split())]
ans = 0
a = 0
b = 0
t = 0

while b != M or a != N:
    if b == M:
        if A[a]+t <= K:
            t += A[a]
            ans += 1
            a += 1
        else:
            break

    elif a == N:
        if B[b]+t <= K:
            t += B[b]
            ans += 1
            b += 1
        else:
            break
    elif B[b] >= A[a] and A[a]+t <= K:
        t += A[a]
        ans += 1
        a += 1
    elif B[b] < A[a]:
        t += B[b]
        ans += 1
        b += 1
    else:
        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()))
ans = 0
C = A + B
C.sort()
for i in range(len(C)):
  if K >= C[i]:
    K = K - C[i]
    ans += 1
  else:
    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()))

if min(A[0],B[0])>K:
    print(0)
Len_A = len(A)
Len_B = len(B)
if sum(A)+sum(B) < K:
    print(N+M)
else:    
    total_time = 0
    counter = 0
    while total_time < K:
        Len_A = len(A)
        Len_B = len(B)
        if Len_A == 0 and Len_B != 0:
            time = B[0]
            choice = "B"
        elif Len_A != 0 and Len_B == 0:
            time = A[0]
            choice = "A"
        elif Len_A!= 0 and Len_B!= 0:
            if A[0] < B[0]:
                time = A[0]
                choice = "A"
            else:
                time = B[0]
                choice = "B"

        total_time += time
        if total_time > K: break
        else:
            counter += 1
            if choice == "A":
                del A[0]
            elif choice == "B":
                del B[0]

    print(counter)

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()))
num = N+M
ans = 0
Atot = 0
for i in range(N):
    Atot += A[i]
    Btot = 0
    for j in range(M):
        Btot += B[j]
        total = Atot + Btot
        if K >= total:
            if i+j+2 >= ans:
                ans = i+j+2
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()))

# print(K)
# print(a)
# print(b)
# N,M=3,4
# K=240
# a=[60, 90, 120]
# b=[80, 150, 80, 150]

ans=0
inf=K*2

for i in range (N+M+10):
    if len(a)==1:
        a.append(inf)
    if len(b)==1:
        b.append(inf)
    A=a[0]
    B=b[0]
    if min(A,B)<=K:
        ans+=1
        K-=min(A,B)
        if A<B:
            a.pop(0)
        elif A>B:
            b.pop(0)
        else:
            if A+a[1]<=B+b[1]:
                a.pop(0)
            else:
                b.pop(0)
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
def aaa():
    n,m,k = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    c = []
    for i,j in zip(a,b):
        if i <= j:
            c.append(i)
            c.append(j)
        else:
            c.append(j)
            c.append(i)
        
    a1 = a
    b1 = b
    a1[0:n+1] = []
    b1[0:m+1] = []
    c = c + a1 + b1
    d = 0
    e = 0
    for i in c:
        if i+e < k:
            e += i
            d += 1
        else:
            return d
    return n + m
aaa()

Submission status: Wrong Answer

Solution code:
N, M , K = map(int, input().split())
A = [int(x) for x in input().split()]
B = [int(y) for y in input().split()]
i = 0
j = 0
count = 0
while K>0:
    if A[i]<=B[j] and i<N and j<M and K>0:
        if A[i] <= K:
            count +=1
            K = K-A[i];
            if i<N-1:
                i+=1
            
            #print(K)
        else:
            K = K-A[i]
    if i==N-1 and j<M and K>0:
        if B[j] <= K:
            count+=1
            K = K-B[j]
            if j<M-1:
                j+=1
            
        else:
            K = K - B[j]
    if A[i] > B[j] and i<N and j < M and K>0:
        if B[j] <= K:
            count+=1
            K = K - B[j]
            if j<M-1:
                j+=1
            
            #print(K)
        else:
            K = K - B[j]
    if j==M-1 and i<N and K>0:
        if A[i] <= K:
            count +=1
            K = K - A[i]
            if i<N-1:
                i+=1
            
        else:
            K = K - A[i]
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

a = input().split()
np_a=np.array(a, dtype='int64')
b = input().split()
np_b=np.array(b, dtype='int64')

ia=0
ib=0
time=0
hon=n+m
for i in range(0,n+m):
  if (ia == n): 
    time+=np_b[ib]
    ib+=1
  elif (ib == m): 
    time+=np_a[ia] 
    ia+=1
  elif (ia < n or ib < m): 
    if (np_a[ia] < np_b[ib]):
      time+=np_a[ia]
      ia+=1
    else:
      time+=np_b[ib]
      ib+=1
    
  if (time > k): 
    hon=i
    break

print (hon)

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()))
    
    A_sum = 0
    A_max = N
    tmp_sum = 0
    if A[0] > K:
        flag = False
    else:
        flag = True
    for i in range(N):
        tmp_sum += A[i]
        if tmp_sum > K:
            A_max = i
            break
        else:
            A_sum = tmp_sum
        
    ans = A_max
    tmp_ans = ans
    #B_sum = 0
    B_i = 0
    time = K - A_sum
    count = 0
    for i in range(-1,A_max):
        if i != -1 and flag:
            A_i = A_max -1 -i
            time += A[A_i]
            count = -1
        tmp_time = time
        next_B_i = B_i
        for j in range(B_i,M):
            tmp_time -= B[j]
            if tmp_time >= 0:
                next_B_i += 1
                count += 1
                time = tmp_time
            else:
                break
                
        B_i = next_B_i
        tmp_ans += count
        if count > 0:
            ans = tmp_ans
            
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import random
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(" ")]

while True:
  if (N>10**8) | (M>10**8) |(K>10**8):
      if random.random()>0.8:
          print(0)
          break
  else:
      time=0
      a_idx=0
      b_idx=0
      count=0
      while time<K:
          count+=1
          try:
              if a_idx+1==N:
                  time+=b[b_idx]
                  b_idx+=1
                  if time>K:
                      count-=1
                  continue
              elif b_idx+1==M:
                  time+=a[b_idx]
                  a_idx+=1
                  if time>K:
                      count-=1
                  continue    

              if a[a_idx]<b[b_idx]:
                  time+=a[a_idx]
                  a_idx+=1

              elif a[a_idx]>b[b_idx]:
                  time+=b[b_idx]
                  b_idx+=1
              else:
                  try:
                      a_com=a_idx
                      b_com=b_idx
                      while True:
                          if a[a_com]>b[b_com]:
                              time+=a[a_idx]
                              a_idx+=1
                              break
                          elif a[a_com]<b[b_com]:
                              time+=b[b_idx]
                              b_idx+=1
                              break
                          a_com+=1
                          b_com+=1
                  except:
                      time+=a[a_idx]
                      a_idx+=1
              if time>K:
                  count-=1            
          except:
              break
      print(count)
      break

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

ans = 0
time = k

while True:
        if a != [] and b != []:
                 if a[0] < b[0]:
                         book = a[0]
                         a.pop(0)
                 elif b[0] <= a[0]:
                         book = b[0]
                         b.pop(0)
        elif a == [] and b == []:
                break
        elif a == [] and b != []:
                book = b[0]
        elif a != [] and b ==[]:
                book = a[0]
                         

        if time >= book:
                time -= book
                ans +=1
        elif time < book:
                break

print(ans)

Submission status: Wrong Answer

Solution code:
# 別変数の整数複数個
M, M, K = [int(x) for x in input().strip().split(" ")]
A = [int(x) for x in input().strip().split(" ")]
B = [int(x) for x in input().strip().split(" ")]

total = 0
cur = 0
while len(A) + len(B) > 0:
    if len(A) == 0:
        total += B.pop(0)
    elif len(B) == 0:
        total += A.pop(0)
    elif A[0] >= B[0]:
        total += A.pop(0)
    else:
        total += B.pop(0)
    if total > K:
        break
    cur += 1
    if len(A) + len(B) == 0:
        break
print(cur)

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



x = 0
while len(A) > 0 and len(B) > 0 and K -  min([A[0], B[0]]) >= 0:
        K = K - min([A[0], B[0]])
        x += 1
        if A[0] <= B[0]:
            del A[0]
        else:
            del B[0]
            
if len(A) == 0 and len(B) > 0:
    while K - B[0] >= 0:
        K = K - B[0]
        x += 1
        del B[0]
        if len(B) == 0:
            break

if len(B) == 0 and len(A) > 0:
    while K - A[0] >= 0:
        K = K - A[0]
        x += 1
        del A[0]
        if len(A) == 0:
            break

print(x)

Submission status: Wrong Answer

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

sumA = []
for i in range(len(listA)):
    if i == 0:
        if listA[i] <= k:
            sumA.append(listA[i])
        else:
            break
    else:
        if sumA[i-1]+listA[i] > k:
            break
        else:
            sumA.append(sumA[i-1]+listA[i])
sumB = []
for i in range(len(listB)):
    if i == 0:
        if listB[i] <= k:
            sumB.append(listB[i])
        else:
            break
    else:
        if sumB[i-1]+listB[i] > k:
            break
        else:
            sumB.append(sumB[i-1]+listB[i])
if len(sumB) > 0 and len(sumA) > 0 and sumB[-1]+sumA[-1] <= k:
    print(n+m)
else:
    maxB = 0
    for iA in range(len(sumA)):
        if sumA[iA] > k:
            break
        for iB in range(len(sumB)):
            if sumA[iA] + sumB[iB] > k:
                break
            else:
                if maxB < iA+1+iB+1:
                    maxB = iA+1+iB+1
    print(maxB)

Submission status: Wrong Answer

Solution code:
import sys

readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda: readline().rstrip() # input string
ni = lambda: int(readline().rstrip()) # input int
nm = lambda: map(int, readline().split()) # input multiple int 
nl = lambda: list(map(int, readline().split())) # input multiple int to list

n, m, k = nm()
a = nl()
b = nl()
ans = 0
sum_a = [0]*(n+1)
sum_b = [0]*(m+1)
for i in range(1, n+1):
    sum_a[i] = sum_a[i-1] + a[i-1]
for i in range(1, m+1):
    sum_b[i] = sum_b[i-1] + b[i-1]
ans = 0
bef_j = m
print(sum_a, sum_b)
for i in range(n+1):
    if sum_a[i] >= k:
        break
    for j in range(bef_j, -1, -1):
        if sum_a[i] + sum_b[j] <= k:
            ans = max(ans, i+j)
            bef_j = j
            break
print(ans)



"""i_n = 0
i_m = 0
while True:
    if i_n >= n and i_m >= m:
        break
    elif i_n >= n:
        tmp = b[i_m]
        i_m += 1
    elif i_m >= m:
        tmp = a[i_n]
        i_n += 1
    else:
        if a[i_n] < b[i_m]:
            tmp = a[i_n]
            i_n += 1
        else:
            tmp = b[i_m]
            i_m += 1

    if tmp + time <= k:
        cnt += 1
        time += tmp
    else:
        break
print(cnt)"""

Submission status: Wrong Answer

Solution code:
N,M,K = [int(s) for s in input().split()]
a = [int(s) for s in input().split()]

b =[int(s) for s in input().split()]

li = []

while True:
    try:
        if a[0]<b[0]:
            li.append(a[0])
            del a[0]
        elif a[0]>b[0]:
            li.append(b[0])
            del b[0]
        elif a[0]==b[0]:
            if a[1]<b[1]:
                li.append(a[0])
                del a[0]
            else:
                li.append(b[0])
                del b[0]
    except:
        break
for i in a:
    li.append(i)
for i in b:
    li.append(i)
total = 0
count = 0

for i in li:
    total += i
    if total <=K:
        count +=1
    else:
        break
print(count)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
A_Read = 0
B_Read = 0
A_Finish = 0
B_Finish = 0
ans = 0
S = 0
while K >= 0:
    if A_Finish == 1 and B_Finish == 1:
        break
    elif A_Finish == 1:
        S += B_list[B_Read]
        # print(B_list[B_Read])
        B_Read += 1
        if B_Read == M:
            B_Finish = 1
    elif B_Finish == 1:
        S += A_list[A_Read]
        # print(A_list[A_Read])
        A_Read += 1
        if A_Read == N:
            A_Finish = 1
    else:
        if A_list[A_Read] <= B_list[B_Read]:
            S += A_list[A_Read]
            # print(A_list[A_Read])
            A_Read += 1
            if A_Read == N:
                A_Finish = 1
        else:
            S += B_list[B_Read]
            # print(B_list[B_Read])
            B_Read += 1
            if B_Read == M:
                B_Finish = 1
    # print(K)
    if K < S:
        break
    elif K == S:
        ans += 1
        break
    # print(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()))
time = 0
count = 0
i = 0
A = 0
while i != n:
    A += a[i]
    if A > k:
        break
    j = 0
    B = 0
    while j != m:
        B += b[j]
        if A + B > k:
            break
        j += 1
    temp = (i+1) + (j+1) - 1
    i += 1
    if temp > count:
        count = temp
print(count)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
x=[int(x) for x in input().split()]
y=[int(x) for x in input().split()]
c=0
cost=0
f,t=0,0
x.sort()
y.sort()
for i in range(n):
    if i<n and cost<k and cost+x[i]<=k and f==0:
        cost+=x[i]
        c+=1
    else:f=1
    if i<m and  cost<k and cost+y[i]<=k and t==0:
        cost+=y[i]
        c+=1
    else:t=1
i+=1
if m>n and t==0:
    while(i<(m)):
        if cost+y[i]<=k and cost<k:
            cost+=y[i]
            c+=1
        i+=1
c1=0
cost=0
for i in range(n):
    if cost+x[i]<=k:
        cost+=x[i]
        c1+=1
c2=0
cost=0
for i in range(m):
    if cost+y[i]<=k:
        cost+=y[i]
        c2+=1
print(max(c1,c2,c))

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
nl= [int(i) for i in input().split()]
ml = [int(i) for i in input().split()]


s = 0;
r = 0;

ni = 0
mi = 0

i=0

sabun = 0

while i < n+m:
    sabun = 0
    if (mi > m-1) :
        sabun = nl[ni]
        if  (sabun + s> k):
            break
        
        r+=1
        s+=nl[ni]
        ni +=1
        i+=1
        continue

    elif (ni>n-1):
        sabun = ml[mi]
        if  (sabun + s > k ):
            break
        
        r+=1
        s+=ml[mi]
        mi +=1
        i+=1
        continue
        
    if (ml[mi]> nl[ni]) :
        sabun = nl[ni]
        if  (sabun + s > k ):
            break
        
        r+=1
        s+=nl[ni]
        ni +=1
    elif (ml[mi] == nl[ni]) :
        if  (mi != n & ni != n) :
            if (ml[mi] <=nl[ni]) :
                sabun = ml[mi]
                if  (sabun + s > k ):
                    break
                r+=1
                s+=ml[mi]
                mi+=1
            if (ml[mi] > nl[ni]) :
                sabun = nl[ni]
                if  (sabun + s > k ):
                    break
                r+=1
                s+=nl[ni]
                ni+=1
                
    else :
        sabun = ml[mi]
        if  (sabun + s > k ):
            break
        
        r+=1
        s+=ml[mi]
        mi+=1

    i+=1
    



print(r)

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 = 0
j = 0
time = 0
ans = 0
for _ in range(n+m+1):
  if A[i] < B[j] and  i != n-1:
    ans +=1
    time += A[i]
    i += 1
  else:
    if j != m-1:
      ans +=1
      time += B[j]
      j += 1
  
  if time > k:
    ans -= 1
    print(ans)
    exit()
  
  if (i+1)+(j+1) == n+m:
    print(n+m)
    exit()

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()))
ans = 0
while k > 0:
    if len(a) == 0 and len(b) == 0:
        break
    elif len(a) == 0 or len(b) == 0:
        if len(a):
            tmp = a[0]
            a.pop(0)
        else:
            tmp = b[0]
            b.pop(0)
    else:
        if a[0] <= b[0]:
            tmp = a[0]
            a.pop(0)
        else:
            tmp = b[0]
            b.pop(0)
    if k - tmp >= 0:
        ans += 1
    k -= tmp
print(ans)