Problem:


Score : 300 points

Problem Statement

We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.

It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).

Consider the following action:

Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.

How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

Constraints

1 \leq N, M \leq 200000

1 \leq K \leq 10^9

1 \leq A_i, B_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M K
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_M

Output

Print an integer representing the maximum number of books that can be read.

Sample Input 1

3 4 240
60 90 120
80 150 80 150

Sample Output 1

3

In this case, it takes us 60, 90, 120 minutes to read the 1-st, 2-nd, 3-rd books from the top on Desk A, and 80, 150, 80, 150 minutes to read the 1-st, 2-nd, 3-rd, 4-th books from the top on Desk B, respectively.

We can read three books in 230 minutes, as shown below, and this is the maximum number of books we can read within 240 minutes.

Read the topmost book on Desk A in 60 minutes, and remove that book from the desk.

Read the topmost book on Desk B in 80 minutes, and remove that book from the desk.

Read the topmost book on Desk A in 90 minutes, and remove that book from the desk.

Sample Input 2

3 4 730
60 90 120
80 150 80 150

Sample Output 2

7

Sample Input 3

5 4 1
1000000000 1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000

Sample Output 3

0

Watch out for integer overflows.



Sample input:
3 4 240
60 90 120
80 150 80 150


Sample output:
3

Submission status: Wrong Answer

Solution code:
import collections

if __name__ == "__main__":
    N, M, K = [int(x) for x in input().split(" ")]
    A = collections.deque([int(x) for x in input().split(" ")])
    B = collections.deque([int(x) for x in input().split(" ")])

    count = 0
    time = 0
    while True:

        if len(A) == 0 and len(B) == 0:
            break

        if len(A) == 0:
            b = B.popleft()
            time += b

            if time > K:
                break
            count += 1
            continue

        if len(B) == 0:
            a = A.popleft()

            time += a
            if time > K:
                break
            count += 1
            continue

        a = A.popleft()
        b = B.popleft()

        if a < b:
            time += a
            if time > K:
                break
            count += 1
            B.appendleft(b)
        else:
            time += b
            if time > K:
                break
            count += 1
            A.appendleft(a)

    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

while time<=k:

    if not a:
        if not b:
            break

        else:
            time+=b[0]
            b.pop(0)
            ans+=1

    elif not b:
        time+=a[0]
        a.pop(0)
        ans+=1

    elif a[0]>=b[0]:
        time+=a[0]
        a.pop(0)
        ans+=1

    elif a[0]<b[0]:
        time+=b[0]
        b.pop(0)
        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()))
 
cnt = 0

while K >= 0:
    if len(a)==0 and len(b)==0:
        cnt += 1
        break
    elif len(a) == 0:
        K -= b.pop(0)
    elif len(b) == 0:
        K -= a.pop(0)
    else:
        if a[0] <= b[0]:
            K -= a.pop(0)
        elif a[0] > b[0]:
            K -= b.pop(0)
    cnt += 1
print(cnt-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()))
    A.append(10000000000)
    B.append(10000000000)
    a, b = 0, 0
    answer = 0

    while True:

        if A[a] < B[b]:
            going_to_read = A[a]
            a += 1
        else:
            going_to_read = B[b]
            b += 1

        if K >= going_to_read:
            answer += 1
            K -= going_to_read
        else: break





    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
# sys.stdin=open('input.txt','r')
# sys.stdout=open('output.txt','w')
from sys import stdin,stdout
from collections import deque,defaultdict
from math import ceil,floor,inf,sqrt,factorial,gcd,log2
from copy import deepcopy
ii1=lambda:int(stdin.readline().strip())
is1=lambda:stdin.readline().strip()
iia=lambda:list(map(int,stdin.readline().strip().split()))
isa=lambda:stdin.readline().strip().split()
mod=1000000007

n,m,k=iia()
arr=iia()
ar=iia()
i,j=0,0
count=0
while i<n and j<m and k>=0:
    if arr[i]>=ar[j]:
        if k>=ar[j]:
            k-=ar[j]
            j+=1
            count+=1
        else:
            break
    elif arr[i]<ar[j]:
        if k>=arr[i]:
            k-=arr[i]
            i+=1
            count+=1
        else:
            break
    else:
        break
while i<n and k>=0:
    if k>=arr[i]:
        k-=arr[i]
        count+=1
        i+=1
    else:
        break
while j<m and k>=0:
    if k>=ar[j] and k>=0:
        count+=1
        k-=ar[j]
        j+=1
    else:
        break
print(count)

Submission status: Wrong Answer

Solution code:
import bisect
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ca = A[:]
cb = B[:]

for i in range(N-1):
  ca[i+1] += ca[i]
for i in range(M-1):
  cb[i+1] += cb[i]

ans = 0
for i in range(N):
  if ca[i] <= K:
    idx = bisect.bisect_right(cb, K-ca[i])
  else:
    continue
  if 0 < idx < M:
    j = idx - 1
  elif idx == 0:
    j = 0
  elif idx == M:
    j = M
  
  ans = max(ans, (i+1)+j)

print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
ans = 0
N = list(map(int,input().split()))
M = list(map(int,input().split()))

for i in range(n+m):
  if len(N) == 0 or len(M) == 0:
    if len(N) == 0:
      temp = M[0]
      M.pop(0)
    else:
      temp = N[0]
      N.pop(0)
  else:
    if N[0] > M[0]:
      temp = M[0]
      M.pop(0)
    else:
      temp = N[0]
      N.pop(0)
  k -= temp
  if k >= 0:
    ans += 1
  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()))

cnt = 0
time = 0
a = A.popleft()
b = B.popleft()

while time <= K:
    if a < b:
        time += a
        try:
            a = A.popleft()
        except:
            a = 10**9 + 1
    else:
        time += b
        try:
            b = B.popleft()
        except:
            b = 10**9 + 1
            
    if a == b == 10**9 + 1:
        break
        
    if time > K:
        break

    cnt += 1

print(cnt)

Submission status: Wrong Answer

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

input = sys.stdin.readline
a,b,n = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
k = 0
j=0
cnt =0
for i in range(a+b):
    if A[k]<=B[j] and a-1!=k :
        cnt+=A[k]
        k+=1
    elif B[j]<A[k] and b-1!=j:
        cnt+=B[j]
        j+=1
    elif A[k]<=B[j] and a-1==k and b-1!=j:
        cnt+=B[j]
        j+=1
    elif B[j]<A[k] and a-1!=k and b-1==j:
        cnt+=A[k]
        k+=1
    else:
        print(a+b)
        sys.exit()


    if cnt > n:
        print(k+j-1)
        sys.exit()
print(k+j)

Submission status: Wrong Answer

Solution code:
n, m, k = [int(i) for i in input().split()]
book_list = [int(i) for i in input().split()]
book_list.extend([int(i) for i in input().split()])

book_list.sort()

times = 0
book_num = 0
for i in book_list:
    if times + i > k:
        break

    times += i
    book_num += 1

print(book_num)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from decimal import Decimal

def main():

    input = stdin.readline

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

    index_A = 0
    index_B = 0

    readtime = 0

    ans = 0
    while True:

        if (index_A >= len(A)) & (index_B >= len(B)):
            break 

        if index_A >= len(A):
            if K >= readtime + B[index_B]:
                readtime += B[index_B]
                index_B += 1
                ans += 1
                continue
            else:
                break
    
        if index_B >= len(B):
            if K >= readtime + A[index_A]:
                readtime += A[index_A]
                index_A += 1
                ans += 1
                continue
            else:
                break


        if A[index_A] < B[index_B]:
            if K >= readtime + A[index_A]:
                readtime += A[index_A]
                index_A += 1
                ans += 1
            else:
                break
        else:
            if K >= readtime + B[index_B]:
                readtime += B[index_B]
                index_B += 1
                ans += 1
            else:
                break


    print(ans)

if __name__ == "__main__":
    main()

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 = []
k2 = 0
t = 0
c = 0
while True:
    if len(a) == 0:
        if len(b) == 0:
            break
        else:
            c = b.pop(0)
    elif len(b) == 0:
        c = a.pop(0)
    elif a[0] <= b[0]:
        c = a.pop(0)
    else:
        c = b.pop(0)
    k2 += c
    if k2 > k:
        break
    else:
        t += 1
print(t)

Submission status: Wrong Answer

Solution code:
I = list(map(int,input().split()))

N = I[0]
M = I[1]
K = I[2]

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

A_top = 0
B_top = 0
time = 0
while time < K:
    if A[0] > K and B[0] > K:
        break

    if A_top >= len(A) and B_top < len(B):
        time += B[B_top]
        B_top += 1

        continue
    
    if B_top >= len(B) and A_top < len(A):
        
        time += A[A_top]  
        A_top += 1
        continue


    if A[A_top] < B[B_top]  :
        
        time += A[A_top]
        A_top += 1
        continue
    if A[A_top] > B[B_top]:
        
        time += B[B_top]
        B_top += 1
        continue
    
    break

result = A_top + B_top
if time > K and result > 0:
    result -= 1

print(result)

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 len(a)>len(b):
	a,b=b,a
i=0
j=0
total=0
cnt=0
while total<k:
	if i<len(a):
		if a[i]<=b[j]:
			total+=a[i]
			i+=1
		else:
			total+=b[j]
			j+=1
	elif j<len(b):
		total+=b[j]
		j+=1

	cnt+=1
	if total>k:
		cnt-=1
	elif total==k:
		break
	if j==len(b) and i==len(a):
		break

print(cnt)

Submission status: Wrong Answer

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

    time = 0
    ans = 0
    for _ in range(M + N):
        a = float('inf') if len(A) == 0 else A[-1]
        b = float('inf') if len(B) == 0 else B[-1]

        if a < b:
            t = A.pop()
            time += t
            ans += 1
        else:
            t = B.pop()
            time += t
            ans += 1

        if time > K:
            ans -= 1
            break
        elif time == K:
            break
    return ans

print(c_tsundoku())

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.pop(0)
alen=len(A)
b = B.pop(0)
blen=len(B)
cnt=0
while (K > 0):
  #print(a,b,alen,blen)
  if alen!=-1 and (a < b):
    if K>=a:
      cnt += 1
      K-=a
      #print(a,alen)
      alen-=1
      if alen >= 0:
        a = A.pop(0)
      else:
        a = float('infinity')
    else:
      break
  elif blen!=-1:
    if K>=b:
      cnt += 1
      K-=b
      #print(b,blen)
      blen-=1
      if blen >= 0:
        b = B.pop(0)
      else:
        b = float('infinity')
    else:
      break
  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()))
count=0
while 1:
	if k==0:
		break
	if len(a)==0 and len(b)==0:
		break
	elif len(a)!=0 and len(b)!=0:
		if a[0]<b[0]:
			k-=a[0]
			count+=1
			a.pop(0)
		else:
			k-=b[0]
			count+=1
			b.pop(0)
	elif len(a)==0 and len(b)!=0:
		if b[0]>k:
			break
		else:
			k-=b[0]
			count+=1
			b.pop(0)
	else:
		if a[0]>k:
			break
		else:
			k-=a[0]
			count+=1
			a.pop(0)
print(count)

Submission status: Wrong Answer

Solution code:
N, M, K = list(map(int, input().split()))
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
total_time = 0
cnt = 0
selected_book = 0
while True:

    if As:
        a_head = As[0]
    else:
        a_head = 10**9
    if Bs:
        b_head = Bs[0]
    else:
        b_head = 10**9

    if a_head > b_head:

        selected_book = Bs.pop(0)
    else:
        selected_book = As.pop(0)

    total_time += selected_book

    if K >= total_time:
        # print("sel" + str(selected_book))
        # print("tot" + str(total_time))
        cnt += 1

    if total_time >= K:
        break
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import deque

n, m, k = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
time = 0
ans = 0
aaa = deque(a)
bbb = deque(b)
while (time < k) & ((len(aaa) > 0)  |  (len(bbb) > 0)):
    if ((len(aaa) > 0)  &  (len(bbb) > 0)):
        if aaa[0] <= bbb[0]:
            time += aaa.popleft()
            ans += 1
        else:
            time += bbb.popleft()
            ans += 1
    elif aaa:
        time += aaa.popleft()
        ans += 1
    elif bbb:
        time += bbb.popleft()
        ans += 1
if time <= k:
    print(ans)
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()))
at=0
bt=0
al=[0]*n
bl=[0]*m
for i in range(n):
  at=at+a[i]
  al[i]=at
for j in range(m):
  bt=bt+b[j]
  bl[j]=bt
t=m-1
ans=0
i=0
while i<n:
  if al[i]+bl[t]<=k:
    ans=max(ans,i+t+2)
    i=i+1
  else:
    t=t-1
  if i==n or t==-1:
    break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque
 
def main():
    N, M, K = map(int, readline().split())
    A = deque([int(i) for i in readline().split()])
    B = deque([int(i) for i in readline().split()])
    cnt = 0
    while (len(A) > 0) or (len(B) > 0):
        if (len(A)>0) and (len(B)>0):
            a = A.popleft()
            b = B.popleft()
            if a <= b:
                K -= a
                B.appendleft(b)
            else:
                K -= b
                A.appendleft(a)
        else:
            if len(A) > 0:
                a = A.popleft()
                K -= a
            if len(B) > 0:
                b = B.popleft()
                K -= b
        if K >= 0:
            cnt += 1
    print(cnt)
if __name__ == '__main__':
    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()))
sum_t = 0
cumsumA = [A[0]]
cumsumB = [B[0]]
ansA = N-1
ansB = M-1
tmp = A[0]
for i in range(1, N):
    tmp = tmp + A[i]
    if tmp > K:
        ansA = i-1
        break
    cumsumA += [tmp]
tmp = B[0]
for i in range(1, M):
    tmp = tmp + B[i]
    if tmp > K:
        ansB = i-1
        break
    cumsumB += [tmp]

ans_t = cumsumA[ansA] + cumsumB[ansB]
ans = ansA + ansB + 2
while K < ans_t:
    ai, bi = A[ansA], B[ansB]
    if ai >= bi:
        ans_t -= ai
        ans -= 1
        ansA -= 1
    else:
        ans_t -= bi
        ans -= 1
        ansB -= 1

print(ans)
# print(ansA, ansB)

Submission status: Wrong Answer

Solution code:

n,m,K=list(map(int,input().split()))
A=[int(j) for j in input().split()]
B=[int(j) for j in input().split()]
i=0
j=0
time=0
cnt=0
while(i<n and j<m):
    one=False
    if(A[i]<=B[j] ):
        x=A[i]
        one=True

    else:
        x=B[j]
    if(x+time<K):
        time=time+x
        if(one):
            i+=1
        else:
            j+=1
        cnt+=1
    else:
        break
if(time<K):
    while(i<n ):
        if(A[i]+time<=K):
            cnt+=1
            i+=1
        else:
            break
    while(j<m ):
        if(B[j]+time<=K):
            cnt+=1
            j+=1
        else:
            break
    # print(time,cnt)
print(cnt)

Submission status: Wrong Answer

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

l.sort()
ll.sort()
ct=0
sm=0
i=j=0

while (i+j)<(n+m) and sm<k:
  if i<n and j<m and l[i]<ll[j] :
    sm+=l[i]
    i+=1
  elif j<m and i<n and l[i]>=ll[j] :
    sm+=ll[j]
    j+=1
  elif i==n and j<m: 
    sm+=ll[j]
    j+=1
  elif i<n:
    sm+=l[i]
    i+=1
if sm>k:
  print(i+j-1)
else:
  print(i+j)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

N, M, K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
count = 0

a_i = 0
b_i = 0

while( K>=0 and count<(N+M) ):
  
  if ( a_i < N and b_i < M ):
    if ( A[a_i] < B[b_i] ):
      K -= A[a_i]
      a_i += 1
      count += 1
    else:
      K -= B[b_i]
      b_i += 1
      count += 1
  else:
    if ( a_i < N ):
      K -= A[a_i]
      a_i += 1
      count += 1
    else:
      K -= B[b_i]
      b_i += 1
      count += 1

if (K<0):
  print(count-1)
else:
  print(count)

Submission status: Wrong Answer

Solution code:

line = input().split(" ")
N = int(line[0])
M = int(line[1])
K = int(line[2])

N_arr = input().split(" ")
M_arr = input().split(" ")

cnt = 0
i_N = 0 
i_M = 0

while(True):
    if(i_N < N):
        N_top = int(N_arr[i_N])
    else:
        N_top = 10000000000

    if(i_M < M):
        M_top = int(M_arr[i_M])
    else:
        M_top = 10000000000

    if(N_top <= K or M_top <= K):
        if(N_top > M_top):
            K = K - M_top
            i_M += 1
        else:
            K = K - N_top
            i_N += 1
        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()))
cost = 0
ans = 0
pa = 0
pb = 0
while True:
	if pa < N and pb < M:
		if A[pa] <= B[pb]:
			cost += A[pa]
			if cost > K:
				break;
			ans += 1
			pa += 1
		else:
			cost += B[pb]
			if cost > K:
				break;
			ans += 1
			pb += 1
	if pa < N and pb >= M:
		cost += A[pa]
		if cost > K:
			break;
		ans += 1
		pa += 1
	if pa >= N and pb < M:
		cost += B[pb]
		if cost > K:
			break;
		ans += 1
		pb += 1
	if pa >= N and pb >= M:
		break;
print(ans)

Submission status: Wrong Answer

Solution code:
def whichDesk(a, b, num=0):
    if num > 5:
        return 1
    if len(a) == 0:
        return 2
    elif len(b) == 0:
        return 1
    elif a[0] > b[0]:
        return 2
    elif a[0] < b[0]:
        return 1
    else:
        return whichDesk(a[1:], b[1:], num+1)

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

t = 0
cnt = 0

while t <= k and (len(a) > 0 or len(b) > 0):
    if whichDesk(a, b) == 2:
        t += b[0]
        b.pop(0)
    else:
        t += a[0]
        a.pop(0)
    if t <= k:
        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()))
time=0
switch=0
for i in range(n):
    if time+a[i]<=k:
        time+=a[i]
    else:
        aread=i
        switch=1
        break
    if switch==0 and i==n-1:
        aread=i+1
ans=aread
read=aread
switch=0
if aread==0:
    for i in range(m):
        if time+b[i]<=k:
            time+=b[i]
            ans+=1
        else:
            print(ans)
            exit()
            switch=1
        if switch==0 and i==m-1:
            print(ans)
            exit()
for i in range(aread):
    time-=a[aread-i-1]
    read-=1
    for j in range(m):
        if time+b[j]<=k:
            time+=b[j]
            read+=1
    ans=max(ans,read)
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 = A[0]
max = 0
for i in range(1,N):
    a += A[i]
    A[i] = a
    if a <= K:
        max = i+1
b = B[0]
if max >= 0:
    L = K-A[max-1]
else:
    L = K
m = 0
for i in range(1,M):
    b += B[i]
    B[i] = b
    if b <= L:
        m = i+1
ans = max+m
if max ==0 and m == 0:
    print(0)
else:
    while(max > 0 and m<M):
        max -= 1
        L = K-A[max-1]
        if m == 0:
            if B[0] <= L:
                m = 1
        if m >= 1:
            while(m<=M and B[m-1]<=L):
                m += 1
        if max + m > ans:
            ans = max+m
    print(ans)

Submission status: Wrong Answer

Solution code:
N,M,V = list(map(int,input().split()))
A=list(map(int,input().split()))
B=list(map(int,input().split()))
S=list(map(int,A+B))
ans=0
time=0
K=sorted(S)
for i in range(N+M):
  if K[0]+time>V:
    print(ans)
    exit()
  else:
    time+=K[0]
    K.pop(0)
    ans+=1

Submission status: Wrong Answer

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

a = list(map(int,input().split()))[::-1]
b = list(map(int,input().split()))[::-1]

#print(a)
#print(b)
ans = 0
while k >= 0:
    #print(k, a,b)
    if b == [] and a == []:
        break
    elif b == [] and a != []:
        if a[-1] <= k:
            k -= a.pop()
            ans += 1
            continue
        else:
            break
    elif a == [] and b != []:
        if b[-1] <= k:
            k -= b.pop()
            ans += 1
            continue
        else:
            break
    if a[-1] > b[-1]:
        if b[-1] <= k:
            k -= b.pop()
            ans += 1
        else:
            break
    else:
        if a[-1] <= k:
            k -= a.pop()
            ans += 1
        else:
            break



print(ans)

Submission status: Wrong Answer

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

a_i, b_i = 0, 0
remain = K
enough = True
count_of_book = 0

while enough:
  enough = False
  if a_i < N and A[a_i] <= remain:
    remain -= A[a_i]
    a_i += 1
    enough = True
    count_of_book += 1
    
  if b_i < M and B[b_i] <= remain:
    remain -= B[b_i]
    b_i += 1
    enough = True
    count_of_book += 1
    
print(count_of_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()))
a=a[::-1]
b=b[::-1]
t=0
ans=0
while len(a)>0 or len(b)>0:
  if len(a)==0:
    tt=b.pop()
    t+=tt
    if t>k:break
    ans+=1
    continue
  if len(b)==0:
    tt=a.pop()
    t+=tt
    if t>k:break
    ans+=1
    continue 
  if a[-1]<=b[-1]:
    tt=a.pop()
    t+=tt
    if t>k:break
    ans+=1
  elif a[-1]>b[-1]:
    tt=b.pop()
    t+=tt
    if t>k:break
    ans+=1
  # if t>k:break
print(ans)

# from collections import deque
# a=deque(a)
# b=deque(b)
# t=0
# ans=0
# while len(a)>0 or len(b)>0:
#   if a[0]<=b[0]:
#     tt=a.popleft()
#     t+=tt
#     ans+=1
#   elif a[0]>b[0]:
#     b.popleft()
#     t+=tt
#     ans+=1
# print(ans)




# c=a+b
# c.sort()
# ans=0
# t=0
# for cc in c:
#   if t<=k:
#     t+=cc
#     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()))

ans = 0
time = 0

while True:
    if len(a) == 0 and len(b) == 0:
        break
    if len(a) < 1:
        b_pop = b.pop(0)
        time += b_pop
        ans += 1
        continue

    if len(b) < 1:
        a_pop = a.pop(0)
        time += a_pop
        ans += 1
        continue

    if a[0] < b[0]:
        a_pop = a.pop(0)
        time += a_pop
    else:
        b_pop = b.pop(0)
        time += b_pop

    if time > k:
        break
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    time = 0
    ans = 0
    for _ in range(n+m+1):
        if time > k:
            print(ans-1)
            return
        else:
            ans += 1
        if a != [] and b != []:
            if a[0] < b[0]:
                time += a[0]
                a.pop(0)
            else:
                time += b[0]
                b.pop(0)
        elif a == [] and b != []:
            time += b[0]
            b.pop(0)
        elif a != [] and b == []:
            time += a[0]
            a.pop(0)
        else:
            print(ans-1)
            return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

    i = 0
    j = 0
    total = 0
    while k > 0:
        a_top = 10 ** 9 + 5
        if i != len(a):
            a_top = a[i]
        b_top = 10 ** 9 + 5
        if j != len(b):
            b_top = b[j]

        if a_top <= b_top:
            k -= a_top
            i += 1
        else:
            k -= b_top
            j += 1

        if k >= 0:
            total += 1
        else:
            break

    print(total)


if __name__ == "__main__":
    main()

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 = 0
count = 0

for i in range(len(a)+len(b)):
  if read <= k:
    if len(a) == 0:
      read += b.pop(0)
      count += 1
    elif len(b) == 0:
      read += a.pop(0)
      count += 1
    elif a[0] < b[0]:
      read += a.pop(0)
      count += 1
    else:
      read += b.pop(0)
      count += 1
  else:
    count -= 1
    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()))
time = 0
count = 0
Ain = 0
Bin = 0
lenA = len(A)
lenB = len(B)
if(min(min(A),min(B))>K):
    print(0)
    exit()
while time<=K:
    
    if((lenA!=Ain) and (lenB!=Bin)):
        if(A[Ain]<B[Bin]):
            time+= A[Ain]
            Ain+=1
            count +=1
        elif(A[Ain]>B[Bin]):
            time += B[Bin]
            Bin+=1
            count+=1
    elif((lenA==Ain) and (lenB==Bin)):
        break
    elif(lenA==Ain):
        time += B[Bin]
        Bin += 1
        count += 1
    elif(lenB==Bin):
        time += A[Ain]
        Ain += 1
        count += 1
if(time == K):
    print(count)
else:
    print(count-1)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
a_li = list(map(int, input().split()))
b_li = list(map(int, input().split()))
a_itr = 0
b_itr = 0
ans = 0
time = 0

while True:
    if a_itr < len(a_li) and b_itr < len(b_li):
        if a_li[a_itr] < b_li[b_itr]:
            time += a_li[a_itr]
            a_itr += 1
        else:
            time += b_li[b_itr]
            b_itr += 1
    elif a_itr < len(a_li):
        time += a_li[a_itr]
        a_itr += 1
    elif b_itr < len(b_li):
        time += b_li[b_itr]
        b_itr += 1
    else:
        break

    if time <= K:
        ans += 1
    else:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,m,k=LI()
  _a=LI()
  _b=LI()
  la=copy.deepcopy(_a)
  lb=copy.deepcopy(_b)

  for i in range(n-1):
    la[i+1]+=la[i]

  for i in range(m-1):
    lb[i+1]+=lb[i]

  # print(la)
  # print(lb)

  cntA=cntB=0
  for i,x in enumerate(la):
    if x>k:
      cntA=i
      break
  if la[-1]<=k:
    cntA=n
  for i,x in enumerate(lb):
    if x>k:
      cntB=i
      break
  if lb[-1]<=k:
    cntB=m

  # print(cntA,cntB)

  mx=max(cntA,cntB)
  # print(mx)

  i=-1
  j=cntB-1
  sm=lb[j]

  while True:
    if i>=n-1 or j<=0:
      break

    if sm<=k:
      i+=1
      sm+=_a[i]

    else:
      sm-=_b[j]
      j-=1

    if sm<=k:
      mx=max(mx,i+j+2)
  # print(mx)

  i=-1
  j=cntA-1
  sm=la[j]

  while True:
    if i>=m-1 or j<=0:
      break

    if sm<=k:
      i+=1
      sm+=_b[i]

    else:
      sm-=_a[j]
      j-=1

    if sm<=k:
      mx=max(mx,i+j+2)

  return mx

# main()
print(main())

Submission status: Wrong Answer

Solution code:
n,m,k=list(map(int,input().split()))
A=list(map(int,input().split())) + [10**9+1]
B=list(map(int,input().split())) + [10**9+1]
time,ans = 0,0
a_idx,b_idx=0,0

while time < k and (a_idx != n or b_idx != m):
  if A[a_idx] <= B[b_idx] and a_idx < n:
    time += A[a_idx]
    a_idx += 1
    ans += 1
  elif A[a_idx] > B[b_idx] and b_idx < m:
    time += B[b_idx]
    b_idx += 1
    ans += 1
    
if time > k:
  print(ans-1)
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
'''
.append(要素) リストに要素を追加
.extend(リスト) リストを連結する
.insert(場所,要素) 指定した場所に要素追加
del 配列名[場所]
-1で末尾で末尾から一つ前

sort()
sorted(reverse=true)

配列の初期化
配列名=[a]*n+[b]*m

Decimal()
'''

from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math
from functools import reduce
from operator import mul
from collections import Counter
import itertools
import fractions
import sys

d1 = stdin.readline().rstrip().split()
N = int(d1[0])
M = int(d1[1])
K = int(d1[2])
A = [int(s) for s in stdin.readline().rstrip().split()]
B = [int(s) for s in stdin.readline().rstrip().split()]

count = 0
minute = 0
while(True):
    if len(A) == 0 and len(B) == 0:
        count += 1
        break
    if len(A) > 0 and (len(B) == 0 or (A[0] <= B[0])):
        num = A.pop(0)
        minute += num
        if minute >= K:
            break
        count += 1
        continue
    if len(B) > 0 and(len(A) == 0 or (B[0] < A[0] and len(B) > 0)):
        num = B.pop(0)
        minute += num
        if minute >= K:
            break
        count += 1
        continue
print(count)