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 = [int(i) for i in input().split()]
book1 = [int(i) for i in input().split()]
book2 = [int(i) for i in input().split()]
book = 0
time = 0
while time < n[2]:
    try:
        if book1[0] < book2[0]:
            time += book1[0]
            book1.pop(0)
            if time <= n[2]:
                book += 1
                time += book2[0]
                book2.pop(0)
                if time <= n[2]:
                    book += 1
                else:
                    break
            else:
                break
        else:
            time += book2[0]
            book2.pop(0)
            if time <= n[2]:
                book += 1
                time += book1[0]
                book1.pop(0)
                if time <= n[2]:
                    book += 1
                else:
                    break
            else:
                break
    except IndexError:
        try:
            if len(book1) != 0:
                time += book1[0]
                book1.pop(0)
                if time <= n[2]:
                    book += 1
                else:
                    break
            else:
                time += book2[0]
                book2.pop(0)
                if time <= n[2]:
                    book += 1
                else:
                    break
        except IndexError:
            break
print(book)

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
y = 0
cnt = 0
cnt2 = 0
sumlist_a = []
sumlist_b = []
while x < k :
    x += a[cnt]
    if x > k:
        break
    cnt += 1
    sumlist_a.append(x)
    if cnt == n:
        break
ans = len(sumlist_a)
sumlist_a.reverse()
sumlist_a.append(0)
#ansがaから全部本をとってこれる最大個数
p=0
for i in sumlist_a:
    while y < k - i:
        y += b[cnt2]
        if y > k - i:
            break
        cnt2 += 1
        if cnt2 == m:
            break
    ans = max(ans, len(sumlist_a)+cnt2-p-1)
    p += 1
    cnt2 = 0
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=list()
c=0
a=0
b=0
for i in range(N+M):
  if a+1<=N and b+1<=M and A[a]<=B[b]:
    C.append(A[a])
    a+=1
  elif a+1<=N and b+1<=M and A[a]>=B[b]:
    C.append(B[b])
    b+=1
  elif a==N:
    C.append(B[b])
    b+=1
  elif b==M:
    C.append(A[a])
    a+=1
import numpy as np
L=np.array(C).cumsum()
print(len(L[L <= K]))

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 = a[::-1]
b = b[::-1]

s = 0
swi = 0
ans = 0
while k>0:
	if len(a)>0 and len(b)>0:
		if a[-1]==b[-1]:
			if swi==0:
				for i in range(2, min(len(a), len(b))+1):
					if a[-i]!=b[-i]:
						if a[-i]>b[-i]:
							swi = -1		
						else:
							swi = 1
						break
				else:
					if len(a)>=len(b):
						swi = 1
					else:
						swi = -1
			if swi==1:
				k-=a.pop()
				if k>=0:ans+=1
			if swi==-1:
				k-=b.pop()
				if k>=0:ans+=1
		elif a[-1]>b[-1]:
			swi = 0
			k-=b.pop()
			if k>=0:ans+=1
		elif a[-1]<b[-1]:
			swi = 0
			k-=a.pop()
			if k>=0:ans+=1
	elif len(a)==0:
		while k>0 and len(b)>0:
			k-=b.pop()
			if k>=0:ans+=1
		break
	elif len(b)==0:
		while k>0 and len(a)>0:
			k-=a.pop()
			if k>=0:ans+=1
		break


print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
if sum(A) + sum(B) <= K:
    print(len(A)+len(B))
else:
    A = deque(A)
    B = deque(B)
    time = 0
    ans = 0
    while time <= K:
        if len(A) == 0:
            time += B[0]
            ans += 1
            B.popleft()
        elif len(B) == 0:
            time += A[0]
            ans += 1
            A.popleft()
        else:
            if A[0] <= B[0]:
                time += A[0]
                ans += 1
                A.popleft()
            else:
                time += B[0]
                ans += 1
                B.popleft()
    print(ans-1)

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()))
  tmp = 0
  count = 0

  if sum(A) + sum(B) <= K:
    return N + M
  elif A[0] > K or B[0] > K:
    return 0

  while True:
    if A[0] < B[0]:
      tmp += A.pop(0)
    else:
      tmp += B.pop(0)
    if tmp > K:
      return count
    count += 1
    if len(A) == 0:
      while True:
        tmp += B.pop(0)
        if tmp > K:
          return count
        count += 1
    elif len(B) == 0:
      while True:
        tmp += A.pop(0)
        if tmp > K:
          return count
        count += 1

print(main())

Submission status: Wrong Answer

Solution code:
import sys
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
abl = sorted(a+b)
ans,cnt = 0,0
if sum(abl) <= k:
	print(len(abl))
	sys.exit()
for i in range(n+m):
	ans += abl[i]
	if abl[i] <= k:
		cnt += 1
	else:
		print(cnt)
		sys.exit()

Submission status: Wrong Answer

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

ans = 0

tmp = [0] * max(N, M)*2
if N < M:
    for i in range(M-N):
        A.append('a')
else:
    for i in range(N-M):
        B.append('a')

for i in range(max(N,M)*2):
    if i%2 == 0:
        tmp[i] = A[i//2]
    else:
        tmp[i] = B[i//2]
        tmp = [_ for _ in tmp if _ != 'a']

for i in range(len(tmp)):
    if K-tmp[i] >= 0:
        K -= tmp[i]
        print('----')
        print(K)
        print(tmp[i])
        print(K-tmp[i])
        ans += 1
    else:
        print(ans)
        exit()


print(ans)

Submission status: Wrong Answer

Solution code:
N ,M ,K = map(int, input().split())
#K = int(K/10)
#print(K)

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

m = 0

for i in range(1, N+1):
    total = A[:i]
    total = sum(total)
    if total > K:
        continue
    mi = i
    for j in range(M):
        total += B[j]
        if total > K:
            break
        #print(total)
        mi += 1

    m = max(m, mi)


print(m)

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_index = 0
b_index = 0
total_read_time = 0
answer = 0
for i in range(N + M):
    if a_index == len(A) and b_index == len(B):
        break
    elif a_index == len(A):
        if total_read_time + B[b_index] > K:
            break
        else:
            answer += 1
            total_read_time += B[b_index]
            b_index += 1
    elif b_index == len(B):
        if total_read_time + A[a_index] > K:
            break
        else:
            answer += 1
            total_read_time += A[a_index]
            a_index += 1
    else:
        if A[a_index] >= B[b_index]:
            if total_read_time + B[b_index] > K:
                break
            else:
                answer += 1
                total_read_time += B[b_index]
                b_index += 1
        else:
            if total_read_time + A[a_index] > K:
                break
            else:
                answer += 1
                total_read_time += A[a_index]
                a_index += 1
print(answer)

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)
    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:
from collections import deque

n, m, k = map(int, input().split())
Alist = deque()
Blist = deque()
Alist.extend(list(map(int, input().split())))
Blist.extend(list(map(int, input().split())))
#print(Alist, Blist)
ABlist = deque()
book = 0
nm = n+m
while (len(ABlist) < nm):
    if (len(Alist) == 0):
        ABlist.extend(Blist)
        break
    elif (len(Blist) == 0):
        ABlist.extend(Alist)
        break

    if (Alist[0] < Blist[0]):
        ABlist.append(Alist[0])
        Alist.popleft()
    else:
        ABlist.append(Blist[0])
        Blist.popleft()
# print(ABlist)
while (True):
    if (len(ABlist) == 0):
        break
    if (k - ABlist[0] >= 0):
        k -= ABlist[0]
        ABlist.popleft()
        book += 1
    else:
        break
print(book)

Submission status: Wrong Answer

Solution code:
from collections import deque

input_data = [input().split() for l in range(3)]
 
limit = int(input_data[0][2])
deskA = deque(input_data[1])
deskB = deque(input_data[2])

num = 0
for i in range(int(input_data[0][0])+int(input_data[0][1])):
  try:
    if not deskA:
      limit -= int(deskB.popleft())
    elif not deskB:
      limit -= int(deskA.popleft())
    elif int(deskA[0]) > int(deskB[0]):
      limit -= int(deskB.popleft())
    else:
      limit -= int(deskA.popleft())
    if limit < 0:
      break
    num += 1
 
  except IndexError:
    break
 
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()))
t = 0
a_i = 0
b_i = 0
while(t <= k):
  if(a_i < len(a) and t + a[a_i] <= k and (b_i == len(b) or a[a_i] <= b[b_i])):
    t += a[a_i]
    a_i += 1
  elif(b_i < len(b) and t + b[b_i] <= k and (a_i == len(a) or b[b_i] < a[a_i])):
    t += b[b_i]
    b_i += 1
  else:
    break
print(a_i + b_i)

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.append(10**10)
b.append(10**10)

waA = [a[0]]
for i in range(1, n + 1):
    waA.append(waA[-1] + a[i])

waB = [b[0]]
for j in range(1, m + 1):
    waB.append(waB[-1] + b[j])

j = 0
mx = 0
for i in reversed(range(n)):
    while waA[i] + waB[j] < k or j == m - 1:
        if mx < (i + 1) + (j + 1):
            mx = (i + 1) + (j + 1)
        j += 1

print(mx)

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

Sa = [0]*N
Sb = [0]*M
Sa[0] = A[0]
Sb[0] = B[0]
a = 0
b = 0
if Sa[0] > K:
    a = 0
else: 
    for i in range(1, N):
        Sa[i] = Sa[i-1] + A[i]
        if Sa[i] > K:
            a = i
            break
    else:
        a = N
if Sb[0] > K:
    b = 0
else:
    for i in range(1, M):
        Sb[i] = Sb[i-1] + B[i]
        if Sb[i] > K:
            b = i
            break
    else:
        b = M

ans = max(a, b)
for i in range(a):
    temp = K - Sa[i]
    if i+1+b <= ans:
        break
    for j in range(b):
        if Sb[j] > temp:
            ans = max(ans, i+1+j)
            break
    else:
        ans = max(ans, i+1+b)
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=[0]*(n+1)
B=[0]*(m+1)
c = 0
#累積和
for i in range(n):
    A[i+1] = A[i] + a[i]
for i in range(m):
    B[i+1] = B[i] + b[i]
#
for i in range(n+1):
    if A[i]>k:
        bookA=i-1
        timeA = A[i-1]
        break
else:
    bookA = n
    timeA = A[n]
    
for i in range(m+1):
    if B[i] >k:
        bookB = i-1
        timeB = B[i-1]
        break
else:
    bookB = m
    timeB = B[m]
#
"""
print(bookA,timeA,)
print(bookB,timeB)
if bookA == 0 and bookB == 0:
    print(0)
    exit()
"""
if bookA < bookB:
    time = timeB
    book = bookB
    for i in range(n+1):
        if k-time < A[i]:
            break
        c = i
    else:
        c = n
    book += c 

elif bookA > bookB:
    book = bookA
    time = timeA
    for i in range(m+1):
        if k-time < B[i]:
            break
        c = i
    else:
        c = m
    book += c

else:
    if timeA > timeB:
        time = timeB
        book = bookB
        for i in range(n+1):
            if k-time < A[i]:
                break
            c = i
        book += c
    elif timeB > timeA:
        time = timeA
        book = bookA
        for i in range(m+1):
            if k-time < B[i]:
                break
            c = i
        book += c

    else:
        if A[bookA-1] > B[bookB-1]:
            book = bookB-1
            for i in range(n+1):
                if A[i] > k:
                    break
                c = i
            book += c
        elif A[bookA-1] < B[bookB-1]:
            book = bookA-1
            for i in range(m+1):
                if B[i] > k:
                    break
                c = i
            book += c
        else:
            book = bookA
            for i in range(m+1):
                if k-timeA < B[i]:
                    book += i-1
            else:
                book += m
if book < 0:
    print(0)
else:
    print(book)

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

count = 0
sum = 0


while i !=  n and j != m:
    if a[i] < b[j]:
        sum += a[i]
        if sum > k:
            print(count)
            exit()
        i += 1
        count += 1
    else:
        sum += b[j]
        if sum > k:
            print(count)
            exit()
        j += 1
        count += 1

if (i == n):
    while j != m:
        sum += b[j]
        if sum > k:
            print(count)
            exit()
        j += 1
        count += 1
while i != n:
    sum += a[i]
    if sum > k:
        print(count)
        exit()
    i += 1
    count += 1

print(n + m)

Submission status: Wrong Answer

Solution code:
import sys
 
n,m,k = map(int, input().split())
a = list(map(int, input().split()))  
b = list(map(int, input().split()))  
 
count_a=0
count_b=0
total=0
 
if k < a[0] and k < b[0] :
    print(0) 
    sys.exit()
 
while(0<=k) :
    
    try:
        ai=a[count_a]
    except :
        ai=None
    try:
        bi=b[count_b]
    except :
        bi=None
    
    if ai is not None and bi is not None :
        if ai < bi :
            k -= ai 
            count_a+=1
        elif bi<ai:
            k-=bi
            count_b+=1
        
        else :
            if count_a < count_b :
                k-= ai 
                count_a+=1
            else :
                k-=bi
                count_b+=1
            
        total+=1
    
    
    elif ai is not None and bi is None :
        
        k-= ai 
        count_a+=1
        
        total+=1
    
    elif ai is None and bi is not None :
        k-=bi
        count_b+=1
        total+=1
        
    else :
        break
 
if k < 0 :
    print(total-1)
else :
    print(total)

Submission status: Wrong Answer

Solution code:
from sys import exit

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

count = 0

while k > 0 :
    az = a[0]
    bz = b[0]
    if az < bz:
        k -= az
        a.remove(az)
    else :
        k -= bz
        b.remove(bz)       
    count += 1
    if len(a) == 0 and len(b) != 0:
        while k > 0 :
            bz = b[0]
            k -= bz
            b.remove(bz)
            count += 1
            if len(b) == 0:
                if k == 0:
                    print(count) 

                else :
                    print(count-1)
                exit()
    if len(b) == 0 and len(a) != 0 :
        while k > 0 :
            az = a[0]
            k -= az
            a.remove(az)
            count += 1
            if len(a) == 0:
                if k == 0:
                    print(count) 

                else :
                    print(count-1)
                exit()            
if k == 0:
    print(count) 

else :
    print(count-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()))

a = 0
b = 0
ans = 0
S = 0
while True:
  if a == N and b == M:
    break
  elif a == N:
    v = B[b]
    b += 1
  elif b == M:
    v = A[a]
    a += 1
  else:
    Va = A[a]
    Vb = B[b]
    if  Va < Vb:
      v = Va
      a += 1
    else:
      v = Vb
      b += 1
  
  S2 = S + v
  if S2 > K:
    a -= 1
    break
  elif S2 == K:
    break
  else:
    S = S2
      
print(a+b)

Submission status: Wrong Answer

Solution code:
n, m ,k = map(int,input().split())
a_list = [int(a) for a in input().split()]
b_list = [int(b) for b in input().split()]
time = 0
a_num = 0
b_num = 0
count = 0

while True:
    
    if (len(a_list) < a_num + 1) and (len(b_list) < b_num + 1): 
        break

    elif  (len(a_list) < a_num + 1) and (len(b_list) >= b_num + 1):
        time += b_list[b_num]      
        b_num += 1
     
    elif (len(a_list) >= a_num + 1) and (len(b_list) < b_num + 1):
        time += a_list[a_num]      
        a_num += 1
        
    elif (len(a_list) >= a_num + 1) and (len(b_list) >= b_num + 1):
        if a_list[a_num] <= b_list[b_num]:
            time += a_list[a_num]
            a_num += 1
        else:
            time += b_list[b_num]      
            b_num += 1
    
    if time <= k:
        count += 1
    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()))
la=len(a)
lb=len(b)
suma=sum(a)
sumb=sum(b)
b.reverse()
b.extend(a)

cnt=0
acnt=lb

flag=0
# print(b)
cos=0
for i in range(lb):
    # print(i,sumb)
    if sumb>k:
        sumb-=b[i]
        cnt+=1
    elif sumb<=k:
        break
satu=lb-cnt
ans=lb-cnt
# print(cnt,la)
if sumb+suma<=k:
    print(satu+la)
    exit()

for i in range(la+lb):
    # print(i,sumb,cnt,acnt)
    if cnt>=lb+2:
        break
    if sumb>k:
        sumb-=b[cnt]
        cnt+=1
        satu-=1
        if cnt==acnt:
            flag=1
            break
    elif sumb<=k:
        sumb+=b[acnt]
        acnt+=1
        if acnt>=la+lb:
            flag=2
            break
        if sumb<=k:
            satu+=1
    # ans=max(ans,satu)
    # print(sumb,cnt,acnt)
    if sumb<=k:

        sin=acnt-cnt
        cos=max(sin,cos)
if sumb<=k:

    sin=acnt-cnt
    cos=max(sin,cos)
if flag==0 or flag==1:
    print(cos)
elif flag==2:
    print(cos)

Submission status: Wrong Answer

Solution code:
from collections import deque
import bisect
N,M,K = list(map(int, input().split()))
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))

if(sum(As) + sum(Bs) <= K):
    print(N + M)
    exit()

Asruisekiwa = []
Bsruisekiwa = []

Asruisekiwa.append(As[0])
Bsruisekiwa.append(Bs[0])

for i, j in enumerate(As[1:]):
    Asruisekiwa.append(Asruisekiwa[-1]+j)

for i, j in enumerate(Bs[1:]):
    Bsruisekiwa.append(Bsruisekiwa[-1] + j)

#print(Asruisekiwa)
#print(Bsruisekiwa)

ans = 0

for index, i in enumerate(Asruisekiwa):
    tmp = i
    maxcheck = K - i

    hoge = bisect.bisect_left(Bsruisekiwa, maxcheck)

    ans = max(ans, index + hoge+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()))

read_time=0
Anum=0
Bnum=0
total=0
while read_time<k:
    if Anum!=len(A) and Bnum!= len(B):
        if (A[Anum]+read_time > k) and(B[Bnum]+read_time > k):
            break
        if A[Anum]<=B[Bnum]:
            read_time+=A[Anum]
            Anum+=1
            total+=1
        else:
            read_time+=B[Bnum]
            Bnum+=1
            total+=1
    elif Anum==len(A) and Bnum!= len(B):
        if (B[Bnum]+read_time > k):
            break
        else:
            read_time+=B[Bnum]
            Bnum+=1
            total+=1
    elif Anum!=len(A) and Anum!= len(B):
        if (A[Anum]+read_time > k):
            break
        else :
            read_time+=A[Anum]
            Anum+=1
            total+=1
    else:
        break

    
print(total)

Submission status: Wrong Answer

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

ans = 0
#ans_time = 0
adex = 0
bdex = 0
c = []
while True:
    if adex < n and bdex < m:
        if a[adex] < b[bdex]:
            #ans_time += a[adex]
            c.append(a[adex])
            adex += 1
        else:
            #ans_time += b[bdex]
            c.append(b[bdex])
            bdex += 1
        ans += 1
    elif adex >= n and bdex < m:
        #ans_time += b[bdex]
        c.append(b[bdex])
        bdex += 1
        ans += 1
    elif adex < n and bdex >= m:
        #ans_time += a[adex]
        c.append(a[adex])
        adex += 1
        ans += 1
    else:
        break
        
    #if ans_time > k:
    #    ans -= 1
    #    break


#print(c)
x = int(0)
i = 0
while i < len(c):
    x += c[i]
    i += 1
    if x > k:
        i -= 1
        break
ans = i

print(max(0,ans))

Submission status: Wrong Answer

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from collections import deque

n,m,k=nii()
a=lnii()
a=deque(a)
b=lnii()
b=deque(b)

t=0
ans=0

while t<=k:
  if a:
    a_c=a[0]
  else:
    a_c=10**18
  if b:
    b_c=b[0]
  else:
    b_c=10**18

  if a_c<=b_c:
    ans+=1
    t+=a_c
    if a:
      z=a.popleft()
#      del a[0]
  else:
    ans+=1
    t+=b_c
    if b:
       z=b.popleft()
#      del b[0]

if ans==0:
  print(0)
else:
  print(ans-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()))
result = 0

A.append(10**10)
B.append(10**10)
i,j = 0,0
for k in range(N+M):
    K -= min(A[i],B[j])
    if K < 0:
        break
    if A[i] <= B[j]:
        i += 1
    else:
        j += 1
    result += 1
print(result)

Submission status: Wrong Answer

Solution code:
a = input().split()
x = input().split()
y = input().split()
z = x + y
zz = []
zz = list(map(lambda i: int(i), z))
t = 0
m = 0
for i in range(len(zz)):
  if t + sorted(zz)[i]< int(a[2]):
    t += sorted(zz)[i]
    m += 1
  else:
    break
    
print(m)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys



def solve(N: int, M: int, K: int, A: "List[int]", B: "List[int]"):
    acount=0
    bcount=0
    nowtime=0
    while True:
        if acount==N and bcount==M:break
        if acount==N:
            if B[bcount]+nowtime>K:break
        elif bcount==M:
            if A[acount]+nowtime>K:break
        else:
            if A[acount]+nowtime>K and B[bcount]+nowtime>K:break
        if acount==N:
            #print("Bfuck")
            nowtime+=B[bcount]
            bcount+=1
            continue
        if bcount==M:
            #print("Afuck")
            nowtime+=A[acount]
            acount+=1
            continue
        if A[acount]==B[bcount]:
            if acount+1<N and bcount+1<M:
                if A[acount+1]<B[bcount+1]:
                    nowtime+=A[acount]
                    acount+=1
                    continue
                else :
                    nowtime+=B[bcount]
                    bcount+=1
                    continue
        if A[acount]<B[bcount]:
            #print("A")
            nowtime+=A[acount]
            acount+=1
        else:
            #print("B")
            nowtime+=B[bcount]
            bcount+=1
    print(acount+bcount)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int(next(tokens)) for _ in range(M)]  # type: "List[int]"
    solve(N, M, K, A, B)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#問3
N,M,K=(int(x) for x in input().split())

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

B=input().split()
B_int = [int(s) for s in B]
  
#print(A_int)
#print(B_int)
#print(K)


sumA=sum(A_int)
sumB=sum(B_int)
all_sum=sumA+sumB

ans=0

while True:
    if len(A_int)==0 and len(B_int)==0:
      #print("pattern 0")
      break
    
    if len(A_int)==0: #Bが空
      if B_int[0]<=K:
        ans+=1
        K=K-B_int[0]
        B_int.pop(0)
        #print("A空 Bいける")
      else:
        break
        
    elif len(B_int)==0: #Aが空
      if A_int[0]<=K:
        ans+=1
        K=K-A_int[0]
        A_int.pop(0)
        #print("B空　A行ける")
      else:
        break
    elif A_int[0] > K and B_int[0] > K :
      #print("A、B　値がきつい")
      break
    
    else:
      if(A_int[0]>B_int[0]):
        ans+=1
        K=K-B_int[0]
        B_int.pop(0)
        #print("A、B両方いけてB")
      else:
        ans+=1
        K=K-A_int[0]
        A_int.pop(0)
        #print("A、B両方いけてB")
    #print(A_int)
    #print(B_int)
    #print(K)

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_np = np.array(A)
B_np = np.array(B)

y=0
for i in range(N+M):
    if K >= min(A_np[0],B_np[0]):
        if A_np[0] < B_np[0]:
            K -= A_np[0]
            np.delete(A_np,0)
            y+=1
        else:
            K -= B_np[0]
            np.delete(B_np,0)
            y+=1
print(y)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, M, K = map(np.int64, input().split())
A = list(map(np.int64, input().split()))
B = list(map(np.int64, input().split()))

time0 = 0
cnt = 0
while(time0<=K):
    if len(A) == 0 and len(B) != 0:
        time0 += B.pop(0)
        cnt += 1
    elif len(B) == 0 and len(A) != 0:
        time0 += A.pop(0)
        cnt += 1
    elif len(A) == 0 and len(B) == 0:
        cnt += 1
        break
    else:
        if A[0] <= B[0]:
            time0 += A.pop(0)
            cnt += 1
        else:
            time0 += B.pop(0)
            cnt += 1
            
cnt -= 1

print(cnt)

Submission status: Wrong Answer

Solution code:
l = input()
l = l.split()
n,m,k = l[0], l[1], int(l[2])
a = input().split()
b = input().split()

ans = 0

x,y = 0, 0

while k > 0:
    if x >= int(n) and y <= int(m) - 1:
        if k - int(b[y]) >= 0:
            k -= int(b[y])
            y += 1
            ans+=1
        else:
            break
    elif y >= int(m) and x <= int(n) - 1:
        if k - int(a[x]) >= 0:
            k -= int(a[x])
            x += 1
            ans+=1
        else:
            break
    elif x >= int(n) and y >= int(m):
        break
    elif int(a[x]) <= int(b[y]):
        if k - int(a[x]) >= 0:
            k -= int(a[x])
            x += 1
            ans+=1
        else:
            break
    else:
        if k - int(b[y]) >= 0:
            k -= int(b[y])
            y += 1
            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()))
cntA = 0
ans = 0
p = max(m,n)
if p == n:
  q = a
  r = b
else:
  q = b
  r = a
for i in range(p):
  if cntA+q[i] > k:
    break
  ans += 1
  cntA += q[i]
indA = ans-1
nc = indA+1
for j in range(indA+1):
  temp = 0
  for v in r:
    if cntA + v > k:
      break
    cntA += v
    temp += 1
  cntA -= q[nc-1-j]
  ans = max(ans,indA+1+temp)
  indA -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ai, bi, ans = 0, 0, 0
time = K

for i in range(N+M):
  if(A[ai] <= B[bi] and time - A[ai] > 0):
    time = time - A[ai]
    if(ai < N-1):
      ai += 1
    ans += 1
  elif(A[ai] > B[bi] and time - B[bi] > 0):
    time = time - B[bi]
    if(bi < M-1):
      bi += 1
    ans += 1

print(ans)
sys.exit()

Submission status: Wrong Answer

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

iter = list(x for x in itertools.chain.from_iterable(itertools.zip_longest(A,B)) if x)
cnt =  0
sum = 0
for i in iter:
    sum += i
    if sum > K:
        break
    else:
        cnt +=1
print(cnt)

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
aindex = n
bindex = m
acumsum = [0]*(n+1)
bcumsum = [0]*(m+1)

ab =0
for aa in range(n):
  if a[aa]<k:
    ab += a[aa]
    acumsum[aa+1] = ab
  else:
    aindex= aa
    break

ab =0
for bb in range(m):
  if b[bb]<k:
    ab += b[bb]
    bcumsum[bb+1]=ab
  else:
    bindex = bb
    break
# print(acumsum,bcumsum)
for i in range(aindex+1):
  for j in range(bindex+1):
    if acumsum[i]+ bcumsum[j] <= k:
      ans = max(ans, i+j)
print(ans)