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

sumA = [A[0]]
sumB = [B[0]]

ans = 0

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

for i in range(M-1):
    if sumB[-1] + B[i+1] <= K:
        sumB.append(sumB[-1] + B[i+1])
    else:
        break

for i in range(len(sumA)):
    for j in range(len(sumB)-1, -1 , -1):
        if (sumA[i] + sumB[j] <= K):
            ans = max(ans, i+j+2)
            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()))

alis=[]
time=0
for i in range(n):
  time+=a[i]
  alis.append(time)
blis=[]
time=0
for i in range(m):
  time+=b[i]
  blis.append(time)
  
import bisect
nowtop=0
for i in range(n):
  aldtime=alis[i]
  books=i
  if aldtime>k:
    break
  else:
    nokoritime=k-aldtime
    books+=bisect.bisect(blis,nokoritime)
    books+=1
    if books>nowtop:
      nowtop=books
print(nowtop)

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
a = 0
b = 0
while True:
    if time > K:
        ans = a+b-1
        break
    if time == K:
        ans = a+b
        break
    if a == N and B == M:
        ans = a+b
        break
    if a == N:
        time += B[b]
        b += 1
    elif b == M:
        time += A[a]
        a += 1
    elif A[a] <= B[b]:
        time += A[a]
        a += 1
    elif B[b] < A[a]:
        time += B[b]
        b += 1
    
print(ans)

Submission status: Wrong Answer

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

count = 0
while k >= 0:
    if bool(reading_time_a) is True and bool(reading_time_b) is True:
        if reading_time_a[0] > reading_time_b[0]:
            if k - reading_time_b[0] >= 0:
                k = k - reading_time_b[0]
                reading_time_b.pop(0)
                count += 1
            else:
                break
        elif reading_time_a[0] < reading_time_b[0]:
            if k - reading_time_a[0] >= 0:
                k = k - reading_time_a[0]
                reading_time_a.pop(0)
                count += 1
            else:
                break
        else:
            if k - reading_time_a[0] >= 0:
                k = k - reading_time_a[0]
                reading_time_a.pop(0)
                count += 1
            else:
                break
    elif bool(reading_time_a) is False and bool(reading_time_b) is False:
        break
    elif bool(reading_time_a) is False:
        if k - reading_time_b[0] >= 0:
            k = k - reading_time_b[0]
            reading_time_b.pop(0)
            count += 1
    elif bool(reading_time_b) is False:
        if k - reading_time_a[0] >= 0:
            k = k - reading_time_a[0]
            reading_time_a.pop(0)
            count += 1
    else:
        break

print(count)

Submission status: Wrong Answer

Solution code:
from sys import stdin

A=list(map(int,stdin.readline().split()))
N=A[0]
M=A[1]
K=A[2]
B=list(map(int,stdin.readline().split()))  #N
C=list(map(int,stdin.readline().split()))  #M
D=dict()
DD=dict()
MAX=0

if B[0]<=K:
    D[(1,0)]=B[0]
if C[0]<=K:
    D[(0,1)]=C[0]

while len(D)>0:
    for t in D:
        if t[0]<N and D[t]+B[t[0]]<=K:
            DD[(t[0]+1,t[1])]=D[t]+B[t[0]]
            MAX=t[0]+t[1]+1
        if t[1]<M and t[0]==0:
            if D[t] + C[t[1]] <= K:
                DD[(t[0],t[1]+1)] = D[t] + C[t[1]]
                MAX = t[0] + t[1] + 1

    D=DD

    DD=dict()


print(MAX)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().strip().split())
a=list(map(int,input().strip().split()))
b=list(map(int,input().strip().split()))
total=0
i=0
j=0
ans=0
while(i<n and j<m and total<k):
  if(a[i]==b[j] and a[i]+b[j]+total<=k):
    total+=(a[i]*2)
    ans+=2
    i+=1
    j+=1
  elif(a[i]==b[j] and a[i]+total<=k):
    total+=a[i]
    ans+=1
    i+=1
  elif(a[i]<b[j] and a[i]+total<=k):
    total+=a[i]
    ans+=1
    i+=1
  elif(b[j]<a[i] and b[j]+total<=k):
    total+=b[j]
    ans+=1
    j+=1
  else:
    break
while(i<n):
  if((a[i]+total)>k):
    break
  total+=a[i]
  ans+=1
  i+=1
while(j<m):
  if((b[j]+total)>k):
    break
  total+=b[j]
  ans+=1
  j+=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()))

a_num = 0
b_num = 0
result = 0
nn = 0

for i in range(n+m):
    if a_num == n and b_num == m:
        break
    elif a_num == n:
        result += b[b_num]
        b_num += 1
        if result >= k:
            break
    elif b_num == m:
        result += a[a_num]
        a_num += 1
        if result >= k:
            break
    elif a[a_num] <= b[b_num]:
        result += a[a_num]
        a_num += 1
        if result >= k:
            break
    else :
        result += b[b_num]
        b_num += 1
        if result >= k:
            break

if result == k:
    print(a_num+b_num)
else:
    print(a_num+b_num-1)

Submission status: Wrong Answer

Solution code:
from itertools import *
n,m,time = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

A = [0]+list(accumulate(a))
B = [0]+list(accumulate(b))
ai = 0
bi = 0
while True:
    if ai < n and bi < m:
        if A[ai+1] + B[bi] > time and A[ai] + B[bi+1] > time:
            break
        elif A[ai+1] +B[bi] > time:
            bi += 1
        elif A[ai] + B[bi+1] > time:
            ai += 1
        else:
            if A[ai+1] - A[ai] >= B[bi+1] - B[bi]:
                bi += 1
            else:
                ai += 1
    elif ai < n and bi == m:
        if A[ai+1] + B[bi] > time:
            break
        else:
            ai += 1
    elif ai == n and bi < m:
        if A[ai] + B[bi+1] > time:
            break
        else:
            bi += 1
    else:
        break
print(ai+bi)

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()))
cnt=0
T=K+1
while(K>0):
  if(A[0]<B[0]):
    read=A[0]
    del A[0]
    A.append(T)
  else:
    read=B[0]
    del B[0]
    B.append(T)
  if(K>=read):
    K-=read
    cnt+=1
  else:
    break
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()))

if K >= sum(A) + sum(B):
    print(N + M)
    exit()
if K < A[0] and K < B[0]:
    print(0)
    exit()
print(N + 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()))
count = 0
ans = 0

for i in range(n + m):
    if a == []:
        if ans + b[0] <= k:
            ans += b[0]
            count += 1
            del(b[0])
    elif b == []:
        if ans + a[0] <= k:
            ans += a[0]
            count += 1
            del(a[0])

    else:
        if ans + min(a[0], b[0]) <= k:
            ans += min(a[0], b[0])
            count += 1
            if a[0] == min(a[0], b[0]):
                del(a[0])
            else:
                del(b[0])

print(count)

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()))
a = deque(a)
b = deque(b)
t = 0
ans = 0
while True:
    if len(a) == 0 and len(b) == 0:
        break
    elif len(a) == 0:
        if t+b[0] > k:
            break
        ans += 1
        t += b.popleft()
    elif len(b) == 0:
        if t+a[0] > k:
            break
        ans += 1
        t += a.popleft()
    else:
        if a[0] < b[0]:
            if t+a[0] > k:
                break
            ans += 1
            t += a.popleft()
        elif a[0] > b[0]:
            if t+b[0] > k:
                break
            ans += 1
            t += b.popleft()
        else:
            if len(a) == 1:
                if t+b[0] > k:
                    break
                ans += 1
                t += b.popleft()
            elif len(b) == 1:
                if t+a[0] > k:
                    break
                ans += 1
                t += a.popleft()
            else:
                if a[1] < b[1]:
                    if t+a[0] > k:
                        break
                    ans += 1
                    t += a.popleft()
                else:
                    if t+b[0] > k:
                        break
                    ans += 1
                    t += b.popleft()
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()))

ln = 0
lm = 0

while (k > 0):
    if (ln >= n):
        s = 10**9+1
    else:
        s = a[ln]

    if (lm >= m):
        t = 10**9+1
    else:
        t = b[lm]

    if (min(s, t) > k):
        break
    elif (s >= t):
        k -= t
        lm += 1
    elif (t >= s):
        k -= s
        ln += 1

print(ln+lm)

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()))
C = N + M
cnt = 0
res = 0
A = deque(A)
B = deque(B)
for c in range(C):
    if A:
        a = A.popleft()
    else:
        a = 10**10+1
    if B:
        b = B.popleft()
    else:
        b = 10**10+1
    if a > b:
        cnt += b
        A.appendleft(a)
    elif a < b:
        cnt += a
        B.appendleft(b)
    if cnt <= K:
        res += 1
    else:
        break
print(res)

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()))
s=0
while(len(A)>0 and len(B)>0 and K>=0):
    if A[0]<=B[0]:
        K-=A[0]
        s+=1
        A.pop(0)
    else:
        K-=B[0]
        s+=1
        B.pop(0)
if K<0:
    print(s-1)
elif K==0:
    print(s)
else:
    if len(A)==0:
        while(len(B)>0 and K>=0):
            K-=B[0]
            s+=1
            B.pop(0)
        if K<0:
            print(s-1)
        else:
            print(s)
    else:
        while(len(A)>0 and K>=0):
            K-=A[0]
            s+=1
            A.pop(0)
        if K<0:
            print(s-1)
        else:
            print(s)

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)
else:
    counter = 0
    total_time = 0
    while total_time < K:
        counter += 1
        Len_A = len(A)
        Len_B = len(B)

        if Len_A == 0 and Len_B!=0:
            choice = "B"
            time = B[0]
        elif Len_B == 0 and Len_A!=0:
            choice = "A"
            time = A[0]
        elif Len_A==0 and Len_B==0: break

        elif A[0]==B[0]:
            j=0 
            for i in range(1,min(Len_A,Len_B)):
                if A[i] != B[i]:
                    next_choice = min(A[i],B[i])
                    if A[i]==next_choice:
                        choice = A[0]
                    else:
                        choice = B[0]
                    break
                j+=1
            if j == len(A)-1:
                choice = "A"
                time = A[0]
            else:
                choice = "B"
                time = B[0]
        else:
            time = min(A[0],B[0])
            if time == A[0]:
                choice = "A"
            elif time == B[0]:
                choice = "B"
        total_time+=time
        if total_time > K:
            counter-=1
            break

        if choice == "A":
            del A[0]
        else:
            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()))
cnt=0
na = 0
mb = 0
while True:
    if na>=n and mb>=m:
        print(cnt)
        break
    elif na>=n:
        k-=b[mb]
        mb+=1
    elif mb>=m:
        k-=a[na]
        na+=1
    elif a[na]>=b[mb]:
        k-=b[mb]
        mb+=1
    else:
        k-=a[na]
        na+=1
    
    if k<0:
        print(cnt)
        break
    else:
        cnt+=1

Submission status: Wrong Answer

Solution code:
from bisect import *
n,m,k=map(int,input().split())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
c=[0]
for i in a:
    c+=[c[-1]+i]
d=[0]
for i in b:
    d+=[d[-1]+i]

ans=j=bisect_left(d,k)-1

for i in range(n+1):
    while c[i]+d[j]>k and c[i]<k:
        j-=1
    if c[i]+d[j]<=k:    
        ans=max(ans,i+j)
print(ans)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
As = input().split()
Bs = input().split()

time = 0
cnt = 0
while True:
  A, B = int(As[0]) , int(Bs[0])
  if A<B:
    if time + A > K:
      break
    time+=A
    del As[0]
    if As == []:
      As.append(10**10)
  else:
    if time + B > K:
      break
    time+=B
    del Bs[0]
    if Bs == []:
      Bs.append(10**10)
  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()))

tmp = []
s = 0
for i in a:
    if s + i <= k:
        tmp.append(i)
        s += i
a = tmp
tmp = []
s = 0
for i in b:
    if s + i <= k:
        tmp.append(i)
        s += i
b = tmp
line = b[::-1] + a

ans = 0
right = 0
sum_ = 0
for left in range(len(line)):
    while right < len(line) and sum_ + line[right] <= k:
        sum_ += line[right]
        right += 1
    l = right -left 
    if l > ans:
        ans = l

    if right == left: right += 1
    else: sum_ -= line[left]

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.sort()
b.sort()
ans=0
i=0
j=0
while (k>=0 and i <max(n,m) and j<max(n,m)):
  temp=min(a[i],b[j]) if i<n and j<m else a[i] if i<n else b[j] 
  k-=temp
  if i<n and temp==a[i]:
      i+=1
  else:
      if j<m:
        j+=1
  
  if k>=0:
    ans+=1
 
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
N, M, k = map(int, input().split())
n = deque(map(int, input().split()))
m = deque(map(int, input().split()))
minutes = 0
count = 0
f = 1
while f:
	if len(m) > 0 and len(n) > 0:
		if minutes + n[0] > k and minutes + m[0] > k: break
		a = 1 if n[0] < m[0] else 0
	elif len(n) == 0 and len(m) > 0: a = 0
	elif len(m) == 0 and len(n) > 0: a = 1

	if a:
		minutes += n[0]
		n.popleft()
	else:
		minutes += m[0]
		m.popleft()
	count += 1
	if len(n) == 0 and len(m) == 0: f = 0
	f = 1 if (len(n) > 0 and minutes + n[0] <= k) or (len(m) > 0 and minutes + m[0] <= k) else 0
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()))


for c in range(abs(M - N) + 3):
    A.append(1000000001)
    B.append(1000000001)

a = 0
b = 0
k = 0
ans = 0

while k <= K:
    if N + M == ans:
        break
    if A[a] >= B[b]: # Bのほうが小さい場合
        k += B[b]
        b += 1
    else: # Aのほうが小さい場合
        k += A[a]
        a += 1
    if k > K:
        break
    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)

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)

atop = 0
btop = 0
zikan = 0
satu = 0
yomu = 0

def hikaku(at, bt):
    global atop, btop, yomu
    if at >= n and bt >= m:
        yomu = a[atop]
        atop += 1
    elif a[at] < b[bt]:
        yomu = a[atop]
        atop += 1
    elif a[at] > b[bt]:
        yomu = b[btop]
        btop += 1 
    else:
        hikaku(at+1, bt+1)

while True:
    if atop >= n and btop >= m:
        break
    if a[atop] < b[btop]:
        yomu = a[atop]
        atop += 1
    elif a[atop] > b[btop]:
        yomu = b[btop]
        btop += 1
    else:
        hikaku(atop+1, btop+1)
    if zikan + yomu <= k:
        zikan += yomu
        satu += 1
    else:
        break
print(satu)

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 = n + m

suma = sum(a)
sumb = sum(b)
sumab = int(suma + sumb)


if sumab <= k:
    print(ans)
    exit()

if a[0] > k and b[0] > k:
    print(0)
    exit()

for i in range(n+m):
    if len(a) == 0:
        sumab = sumab - b[-1]
        del b[-1]
        ans -= 1
        if sumab <= k:
            print(ans+1)
            exit()
    elif len(b) == 0:
        sumab = sumab - a[-1]
        del a[-1]
        ans -= 1
        if sumab <= k:
            print(ans+1)
            exit()
    elif a[-1] >= b[-1]:
        sumab = sumab - a[-1]
        del a[-1]
        ans -= 1
        if sumab <= k:
            print(ans+1)
            exit()
    elif a[-1] < b[-1]:
        sumab = sumab - b[-1]
        del b[-1]
        ans -= 1
        if sumab <= k:
            print(ans+1)
            exit()
    #print(sumab)

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()))
def func(A,B,k):
    i=0
    j=0
    time=0
    cnt=0
    while time<=k:
        if i==len(A) and j==len(B):
            cnt=1
            break
        elif i==len(A):
            time+=B[j]
            j+=1
            continue
        elif j==len(B):
            time+=A[i]
            i+=1
            continue

        if A[i]<=B[j]:
            time+=A[i]
            i+=1
        elif A[i]>B[j]:
            time+=B[j]
            j+=1    
    print(i+j-1+cnt)
func(A,B,k)

Submission status: Wrong Answer

Solution code:
from collections import deque
n, m, k = map(int, input().split())
a = deque(list(map(int, input().split())))
b = deque(list(map(int, input().split())))

ans = 0
while True:
    # aにもbにも本がない場合ブレーク
    if not a and not b:
        break
    # aに本がなく、bに本がある場合はbからpop
    if not a and b:
        x = b.popleft()
    # その逆
    elif not b and a:
        x = a.popleft()
    # どちらにも本がある場合
    elif a and b:
        if a[0] <= b[0]:
            x = a.popleft()
        else:
            x = b.popleft()
    if x <= k:
        ans += 1
        k -= x
    else:
        break

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np

n, m, k = [int(e) for e in input().split()]
a = np.array([int(e) for e in input().split()])
b = np.array([int(e) for e in input().split()])

asum = a.cumsum()
bsum = b.cumsum()

#aのみbのみ
onlya = (asum < k).sum()
onlyb = (bsum < k).sum()
ans = max(onlya,onlyb)

for i,t in enumerate(asum):
    for j,s in enumerate(bsum):
        if t+s <= k and i+j+2 > ans:
            ans = i+j+2
        if t+s > k:
            break

print(ans)

Submission status: Wrong Answer

Solution code:
# Tsundoku
N, M, K = map(int, input().split())
a_int = list(map(int, input().split()))
b_int = list(map(int, input().split()))

min_book = min(len(a_int), len(b_int))
max_book = max(len(a_int), len(b_int))

time = 0 #時間
count = 0 #冊数
for i_common in range (0, min_book):
    t = a_int[i_common] + b_int[i_common]
    if time + t <= K:
        time += t
        count += 2
    elif time + t > K:
        if time + a_int[i_common] <= K:
            time += a_int[i_common]
            count += 1

#aとbの冊数同じならここまででOK
#aの方が多い時
if len(a_int) > len(b_int):
    for i_ori in range(min_book, max_book):
        if time + a_int[i_ori] <= K:
            time += a_int[i_ori]
            count += 1

#bの方が多い時
if len(a_int) < len(b_int):
    for i_ori in range(min_book, max_book):
        if time + b_int[i_ori] <= K:
            time += b_int[i_ori]
            count += 1

print(count)

Submission status: Wrong Answer

Solution code:
from itertools import zip_longest

N, M, K = map(int, input().split())
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]
S = sum(A) + sum(B)
S_len = len(A) + len(B)
if K >= S:
    print(S_len)
else:
    ans = 0
    while K >= 0:
        for a, b in zip_longest(A, B):
            if K < 0:
                break
            if a:
                if K < 0:
                    break
                K -= a
                ans += 1
            if b:
                if K < 0:
                    break
                K -= b
                ans += 1
    print(ans - 1)

Submission status: Wrong Answer

Solution code:
import numpy as np
N,M,K = [int(num) for num in input().split()]
A_list = np.array([int(num) for num in input().split()])
B_list = np.array([int(num) for num in input().split()])

read_min = K
read_cnt = 0
ai = 0
bi = 0



for _ in range(N+M):
  if ai < N and bi < M:
    if A_list[ai] < B_list[bi]:
      read_min -= A_list[ai]
      ai += 1
    elif A_list[ai] >= B_list[bi]:
      read_min -= B_list[bi]
      bi += 1
  else:
    if ai >= N:
      read_min -= B_list[bi]
      bi += 1
    elif bi >= M:
      read_min -= A_list[ai]
      ai += 1
    else:
      break
    
  if read_min < 0:
    break
  read_cnt += 1  


print(read_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()))
AB = list()
ai = 0
bi = 0
time = 0
num = 0
leng = len(A) + len(B)
for _ in range(leng):
  if ai == len(A) and bi == len(B):
    break
  elif ai == len(A):
    AB.append(B[bi])
    bi += 1
  elif bi == len(B):
    AB.append(A[ai])
    ai += 1
  elif A[ai] <= B[bi]:
    AB.append(A[ai])
    ai += 1
  else:
    AB.append(B[bi])
    bi += 1
#  print(AB)
#  print('ai:',ai,'bi:',bi)
for i in range(leng):
  time += AB[i]
  if time <= K:
    num += 1
  else:
    break
print(num)

Submission status: Wrong Answer

Solution code:
from collections import deque
N,M,K = map(int,input().split())
A = deque(map(int,input().split()))
B = deque(map(int,input().split()))
ans = N+M
time = sum(A) + sum(B)
if time <= K:
    print(ans)
    exit()

#後ろから抜いていく
while time > K:
    if len(A) == 0 and len(B) == 0:
        print(ans)
        exit()
    
    elif len(A) > 0 and len(B) > 0:
        if A[-1] > B[-1]:
            time -= A[-1]
            ans -= 1
            A.pop()
        else:
            time -= B[-1]
            ans -= 1
            B.pop()
    elif len(A) == 0 and len(B) > 0:
        time -= B[-1]
        ans -= 1
        B.pop()
    else:
        time -= A[-1]
        ans -= 1
        A.pop()
   
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()))
books = sorted(A + B)

for i, t in enumerate(books):
  if K < t:
    ans = i
    break
  K -= t
else:
  ans = len(books)
  
print(ans)

Submission status: Wrong Answer

Solution code:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
t_sum = 0
cnt = 0
flag = True

for _ in range(500000):
  if A == []:
    for _ in range(len(B)+1):
      if B == []:
        flag = False
        break
      t_sum += B[0]
      cnt += 1
      B = B[1:]
      if t_sum > K:
        cnt -= 1
        flag = False
        break
  if not flag:
    break
  if B == []:
    for _ in range(len(A)+1):
      if A == []:
        flag = False
        break
      t_sum += A[0]
      cnt += 1
      A = A[1:]
      if t_sum > K:
        cnt -= 1
        flag = False
        break
  if not flag:
    break
  if A[0] <= B[0]:
    t_sum += A[0]
    cnt += 1
    A = A[1:]
  else:
    t_sum += B[0]
    cnt += 1
    B = B[1:]
  if t_sum > K:
    cnt -= 1
    break
  
print(cnt)

Submission status: Wrong Answer

Solution code:
def select_table(A, B):
    if len(A) == 0:
        return 'B'
    if len(B) == 0:
        return 'A'
    if (len(A) == 1)&(len(B) == 1)&(A[0] == B[0]):
        return 'A'
    if A[0] < B[0]:
        return 'A'
    elif A[0] > B[0]:
        return 'B'
    else:
        if len(A) == 1:
            next_A = []
        else:
            next_A = A[1:]
        if len(B) == 1:
            next_B = []
        else:
            next_B = B[1:]
        select_table(next_A, next_B)

if __name__ == "__main__":
    N, M, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    ans = 0
    while((K > 0)&(ans < N+M)):
        if select_table(A, B) == 'A':
            K -= A[0]
            A = [] if len(A) == 1 else A[1:]
            if K > 1:
                ans += 1
        else:
            K -= B[0]
            B = [] if len(B) == 1 else B[1:]
            if K >= 0:
                ans += 1
    print(ans)

Submission status: Wrong Answer

Solution code:
import heapq as hq
def inp():
	return (int(input()))


def inlt():
	return (list(map(int,input().split())))


def insr():
	s=input()
	return (list(s[:len(s)]))


def invr():
	return (map(int,input().split()))


def subset_sum_count(arr,n,sum):
	dp=[[0 for _ in range(sum+1)] for _ in range(n+1)]
	for i in range(n+1):
		for j in range(sum+1):
			if j==0:
				dp[i][j]=1
			elif arr[i-1]<=j:
				dp[i][j]=dp[i-1][j-arr[i-1]]+dp[i-1][j]
			else:
				dp[i][j]=dp[i-1][j]
	return dp[n][sum]


def prefix(a):
	pre=[]
	pre.append(a[0])
	for i in range(1,len(a)):
		pre.append(pre[i-1]+a[i])
	return pre

def str_to_integer_list(n):
	a=[]
	for i in range(len(n)):
		a.append(int(n[i]))
	return a
def list_to_str(l):
	s=""
	for i in l:
		s+=str(i)
	return s
def binarySearch(arr,low,high,x):
	if (high>=low):
		mid=low+(high-low)//2
		if x==arr[mid]:
			return (mid)
		elif (x>arr[mid]):
			return binarySearch(arr,(mid+1),high,x)
		else:
			return binarySearch(arr,low,(mid-1),x)
	
	return -1


def right_shift(a,s):
	return a[s:]+a[:s]


def dijkstra(s,N,E):
	visited=set()
	dist={}
	for i in range(1,N+1):
		dist[i]=1<<29
	queue=[(dist[i],i) for i in range(1,N+1)]
	hq.heappush(queue,(0,s))
	dist[s]=0
	while queue:
		d,u=hq.heappop(queue)
		if u in visited:
			continue
		#Relax all the neighbours of u
		for t in E[u]:
			v,r=t
			if dist[v]>d+r:
				dist[v]=d+r
				hq.heappush(queue,(dist[v],v))
		#Node u has been processed
		visited.add(u)
	return dist


def path(start,end,parent):
	path=[end]
	while path[-1]!=start:
		path.append(parent[path[-1]])
	path.reverse()
	return path


def bfs(graph,start,end):
	parent={}
	queue=[]
	queue.append(start)
	while queue:
		node=queue.pop(0)
		if node==end:
			return path(start,end,parent)
		for next in graph.get(node,[]):
			if node not in queue:
				parent[next]=node
				queue.append(next)


'''for _ in range(int(input())):
	n,m=list(map(int,input().split()))
	graph=[[]for _ in range(n+1)]
	distance=[-1]*(n+1)
	visited=[False]*(n+1)
	for _ in range(m):
		x,y=list(map(int,input().split()))
		graph[x].append(y)
		graph[y].append(x)'''
'''T = int(input())
for i in range(0, T):
	N, M = map(int, input().split(' '))
	graph = {}
	for j in range(1, N+1):
		graph[j] = []
	for j in range(0, M):
		x, y, r = map(int, input().split(' '))
		graph[x].append((y,r))
		graph[y].append((x,r))'''
n,m,k=invr()
a=inlt()
b=inlt()
i=0;j=0
c=[]
while i<len(a) and j<len(b):
	c.append(a[i])
	c.append(b[i])
	i+=1
	j+=1
while i<len(a):
	c.append(a[i])
	i+=1
while j<len(b):
	c.append(b[j])
	j+=1
count=0
s=0
i=0
x=prefix(c)
for i in x:
	if i<=k:
		count+=1
print(count)

Submission status: Wrong Answer

Solution code:
from heapq import heapify, heappop, heappush
N, M, K = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
A.sort()
B.sort()
cur = 0
ans = 0
heapify(A)
heapify(B)
while cur <= K and ans < N+M:
    if len(A) != 0 and len(B) != 0:
        a = heappop(A)
        b = heappop(B)
        if a <= b:
            cur += a
            if cur > K:
                break
            heappush(B, b)
            ans += 1
        else:
            cur += b
            if cur > K:
                break
            heappush(A, a)
            ans += 1
    elif len(A) == 0:
        b = heappop(B)
        cur += b
        if cur > K:
            break
        ans += 1
    elif len(B) == 0:
        a = heappop(A)
        cur += a
        if cur > K:
            break
        ans += 1
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
n = 0
m = 0
s = 0
for i in range(len(A) + len(B)):
    if n <= len(A)-1 and m <= len(B)-1:
        if A[n] < B[m]:
            s += A[n]
            ans += 1
            n += 1
        else:
            s += B[m]
            ans += 1
            m += 1
    elif n <= len(A) - 1 and m == len(B):
        s += A[n]
        ans += 1
        n += 1    
    elif n == len(A) and m <= len(B)-1:
        s += B[m]
        ans += 1
        m += 1    
    if s > K:
        print(ans-1)
        exit()
    elif s == K:
        print(ans)
        exit()
print(ans)