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

num = 0
cnt = 0

i, j = 0, 0

while i<len(a) and j<len(b):
  if a[i] < b[j]:
    if num+a[i] <= k:
      num += a[i]
      cnt += 1
      i += 1
    else:
      break
  else:
    if num+b[j] <= k:
      num += b[j]
      cnt += 1
      j += 1
    else:
      break


while i < len(a):
  if num+a[i]<=k:
    num += a[i]
    cnt += 1
    i += 1
  else:
    break

while j < len(b):
  if num+b[j]<=k:
    num += b[j]
    cnt += 1
    j += 1
  else:
    break


print(cnt)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right as br


def main():
    n, m, k = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    tmp = 0
    a = 0
    b = 0
    Sb = [B[0]]
    for i in range(1, m):
        Sb.append(Sb[-1] + B[i])
    Sa = [A[0]]
    for i in range(1, n):
        Sa.append(Sa[-1] + A[i])
    mx = 0
    for j in range(n):
        index = br(Sb, k - Sa[j]) - 1
        tmp = Sa[j] + Sb[index] if index > 0 else Sa[j]
        if tmp <= k:
            mx = max(mx, j + index + 2)
    mx = max(mx, j + index)
    print(mx)
    return


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math

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

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

list_ = []
cnt=0
finish_flg = False
while (len(a_list)!=0) & (len(b_list)!=0):
  a_top = a_list[-1]
  b_top = b_list[-1]

  if a_top<b_top:
    list_.append(a_top)
    a_list.pop()
  else:
    list_.append(b_top)
    b_list.pop()
  
  if sum(list_)>k:
    break
  else:
    cnt+=1
    
nokori_hon = a_list + b_list
keika_jikan = sum(list_)
while len(nokori_hon)!=0:
  keika_jikan += nokori_hon.pop()
  if keika_jikan > k:
    break
  else:
    cnt+=1

print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import deque
import sys
N, M, K = map(int,input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

dA = deque(A)
dB = deque(B)
if dA:
    A = dA.popleft()
else:
    A = float('INF')
if dB:
    B = dB.popleft()
else:
    B = float('INF')

mysum = 0
myans = 0
while myans < (N+M):
    if mysum + min(A,B) <= K:
        mysum += min(A,B)
        myans += 1
        #print(myans , mysum)
        if min(A,B) == A:
            if dA:
                A = dA.popleft()
            else:
                A = float('INF')
        else:
            if dB:
                B = dB.popleft()
            else:
                B = float('INF')
            
    else:
        print(myans)
        sys.exit()
print(myans)

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 search(a, b, time):
    check = False
    
    if a > len(A) - 1:
        if b > len(B) - 1:
            check = True
        else:
            time += B[b]
            b += 1
    else:
        if b > len(B) - 1:
            if a > len(A) - 1:
                check = True
            else:
                time += A[a]
                a += 1
        else:
            if A[a] > B[b]:
                time += B[b]
                b += 1
            else:
                time += A[a]
                a += 1
    
    return a, b, time, check

a = 0
b = 0
time = 0

for n in range(200000 * 200000):
    a, b, time, check = search(a, b, time)
    
    if check:
        print(a + b)
        break

    if time > K:
        print(a + b - 1)
        break

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
from itertools import accumulate


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


N, M, K = zz()
A = zz()
B = zz()
# 累積和を見てみる
A_sum = list(accumulate(A))
B_sum = list(accumulate(B))
a_idx = 0
b_idx = 0
# a_idx + b_idx を最大化
# K >= A_sum[a_idx+1] + B_sum[b_idx+1]
a_idx = bisect.bisect(A_sum, K) - 1
# a_read = a_idx
a_time = A_sum[a_idx-1]
ans = a_idx
if (a_idx == -1):
    b_idx = bisect.bisect(B_sum, K)
    print(b_idx)
    exit()
else:
    for b_idx in range(M):
        # print(B_sum[b_idx] + A_sum[a_idx], a_idx, b_idx)
        while (B_sum[b_idx] + A_sum[a_idx] > K):
            a_idx -= 1
            if (a_idx < 0):
                print(max(ans, 0))
                exit()
        ans = max(ans, a_idx+b_idx+2)

print(max(ans, 0))

Submission status: Wrong Answer

Solution code:
a=input().split(" ")
b=input().split(" ")
c=input().split(" ")
d=0
e=0
f=0
count=0
while int(a[2])>=e and int(a[2])>=int(b[0]):
    if d<int(a[0]):
        e=e+int(b[d])
        d=d+1
        count+=1
    elif f<int(a[1]) and d>=3:
        e=e+int(c[f])
        f=f+1
        count+=1
    elif d>int(a[0]) and f>int(a[1]):
        d=0 
        f=0
    else:
        break

print(count)

Submission status: Wrong Answer

Solution code:
import itertools
def main():
    n,m,k=map(int, input().split())
    a=[int(i) for i in input().split()]
    b=[int(i) for i in input().split()]
    lis = []
    time = 0
    res = 0
    ai=0
    bi=0

    while(1):
        if(ai==n):
            lis += b[bi:]
            break
        if(bi==m):
            lis += a[ai:]
            break
        if(a[ai]<b[bi]):
            lis.append(a[ai])
            ai+=1
        else:
            lis.append(b[bi])
            bi+=1

    for i in lis:
        time += i
        if(time > k):
            break
        res+=1
    print(res)



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

sa=[0]*n
sb=[0]*m
s=0
for i in range(n):
  s+=a[i]
  sa[i]=s
s=0
for i in range(m):
  s+=b[i]
  sb[i]=s

def getb(kb, start):
  global sb,m
  i=start
  while sb[i]<kb:
    i+=1
    if i>=m-1:
      return m-1
  return i-1

ans=0
for i in range(n):
  for j in range(m):
    if sa[i]+sb[j] <= k:
      ans=i+j+2

print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
aans=0
bans=0
atime=0
btime=0
ans=0
for i in range(len(a)):
    btime=0#btimeでbの和についてのリストを使うと高速化できそうcumsumあたりで
    atime=atime+a[i]
    if atime>k:
        break
    else:
        for j in range(len(b)):
            btime=btime+b[j]
            if atime+btime<=k:
                if ans<=i+j+2:
                    ans=i+j+2
            else:
                break
print(ans)

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

new_a=[]
new_b=[]
add=0
add_a=0
for i in a:
    if add+i<=k:
        new_a.append(i)
        add_a+=i
    add+=i

add=0
add_b=0
for j in b:
    if add+j<=k:
        new_b.append(j)
        add_b+=j
    add+=j

print(new_a,new_b)

add=0
if len(new_a)>len(new_b):
    k-=add_a
    count=len(new_a)
    for i in new_b:
        if add+i<k:
            count+=1
elif len(new_b)>len(new_a):
    k-=add_b
    count=len(new_b)
    for i in new_a:
        if add+i<k:
            count+=1
else:
    if add_a < add_b:
        k-=add_a
        count=len(new_a)
        for i in new_b:
            if add+i<k:
                count+=1
    else:
        k-=add_b
        count=len(new_b)
        for i in new_a:
            if add+i<k:
                count+=1

print(count)

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
while True:
    if adex < n and bdex < m:
        if a[adex] <= b[bdex]:
            ans_time += a[adex]
            adex += 1
        else:
            ans_time += b[bdex]
            bdex += 1
        ans += 1
    elif adex >= n and bdex < m:
        ans_time += b[bdex]
        bdex += 1
        ans += 1
    elif adex < n and bdex >= m:
        ans_time += a[adex]
        adex += 1
        ans += 1
    else:
        break

    #print(ans,ans_time)

    if ans_time > k:
        ans -= 1
        break



print(ans)

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

AB = A+B
AB = sorted(AB)
print(A,B,AB)

count=0
jikan=0
for i in range(len(AB)):
    jikan+=AB[i]
    if jikan<=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()))
count = 0
Ain = 0
Bin = 0
check = False
if(min(min(A),min(B))>K):
    print(0)
while K>=0:
    if(Ain != N and Bin !=M): 
        if(A[Ain] < B[Bin]):
            K-=A[0]
            Ain += 1
        else:
            K-=B[0]
            Bin += 1
        
    elif((Ain == N) and (Bin == M)):
        check = True
        break
    if(Ain==N):
        K -= B[Bin]
        Bin += 1
    elif(Bin==M):
        K -= A[Ain]
        Ain += 1
if(K==0 or check):
    print(Ain+Bin)
else:
    print(Ain+Bin-1)

Submission status: Wrong Answer

Solution code:
from heapq import merge 
m,n,k=map(int,input().split())
l=list(map(int,input().split()))
li=list(map(int,input().split()))
r=list(merge(l,li)) 
z,ans=0,0
for i in r:
  z+=i
  if z>k:
    break
  ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque

n, m, k = map(int, input().split())
INF = 10**18
A = deque(list(map(int, input().split())) + [INF])
B = deque(list(map(int, input().split())) + [INF])
total = 0
cnt = 0
while True:
    if A[0] < B[0]:
        a = A.popleft()
        total += a
    else:
        b = B.popleft()
        total += b
    if total > k:
        break
    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()))
number=0
s=0
while 1 :
  if a[0]<=b[0] and s+a[0]<=k:
    number+=1
    s=s+a[0]
    a.pop(0)
  elif a[0]>b[0] and s+b[0]<=k:
    number+=1
    s=s+b[0]
    b.pop(0)
  else:
    break
  if len(a)==0:
    a.append(10**10)
  if len(b)==0:
    b.append(10**10)
print(number)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
t=0
for p in range(n):
    if t+a[p]>k:
        p-=1
        break
    t+=a[p]
for q in range(m):
    if t+b[q]>k:
        q-=1
        break
    t+=b[q]
ans=p+q+2
if q<m-1:
    z=ans
    r=0
    for s in range(p,-1,-1):
        t-=a[s]
        z-=1
        while r<m and t+b[r]<=k:
            t+=b[r]
            r+=1
            z+=1
        if z>ans:
            ans=z
        if r==m-1:
            break
print(ans)

Submission status: Wrong Answer

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

T = 0

index_a = 0
index_b = 0
count = 0
A_len = len(A) - 1 #index最大値
B_len = len(B) - 1

while T < K and (index_a <= A_len or index_b <= B_len):
    if index_a <= A_len and index_b <= B_len:
            
        if A[index_a] <= B[index_b]:
            if T + A[index_a] > K:
                break
            else:
                T += A[index_a]
                index_a += 1
        else:
            if T + B[index_b] > K:
                break
            else:
                T += B[index_b]
                index_b += 1

    elif index_a > A_len:
        if T + B[index_b] > K:
            break
        else:
            T += B[index_b]
            index_b += 1
    else:
        if T + A[index_a] > K:
            break
        else:
            T += A[index_a]
            index_a += 1

    count += 1
    
print(count)

Submission status: Wrong Answer

Solution code:
a, b, c = list(map(int, input().split()))
d = list(map(int, input().split()))
e = list(map(int, input().split()))
n = 0
while True:
  try: 
    if d[0] > e[0]:
      c -= e[0]
      e.pop(0)
    else:
      c -= d[0]
      d.pop(0)
  except IndexError:
    if len(d) == 0 and len(e) == 0:
      break
    if len(d) == 0:
      c -= e[0]
      e.pop(0)
    else:
      c -= d[0]
      d.pop(0)
  n += 1
  if c < 0:
    break
print(n)

Submission status: Wrong Answer

Solution code:

import sys, io, os, re
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor, ceil
from copy import copy, deepcopy
from collections import deque
from fractions import gcd
from functools import reduce
from itertools import groupby
from heapq import heapify, heappush, heappop

# sys.setrecursionlimit(5000)

n1 = lambda: int(sys.stdin.readline().strip())
nn = lambda: list(map(int, sys.stdin.readline().strip().split()))
f1 = lambda: float(sys.stdin.readline().strip())
fn = lambda: list(map(float, sys.stdin.readline().strip().split()))
s1 = lambda: sys.stdin.readline().strip()
sn = lambda: list(sys.stdin.readline().strip().split())
nl = lambda n: [n1() for _ in range(n)]
fl = lambda n: [f1() for _ in range(n)]
sl = lambda n: [s1() for _ in range(n)]
nm = lambda n: [nn() for _ in range(n)]
fm = lambda n: [fn() for _ in range(n)]
sm = lambda n: [sn() for _ in range(n)]

def array1(n, d=0): return [d] * n
def array2(n, m, d=0): return [[d] * m for x in range(n)]
def array3(n, m, l, d=0): return [[[d] * l for y in xrange(m)] for x in xrange(n)]
def linc(A, d=1): return map(lambda x: x + d, A)
def ldec(A, d=1): return map(lambda x: x - d, A)

def bsch(lower, upper, judge):
    while True:
        if lower == upper:
            return lower

        x = (upper + lower) // 2
        if judge(x):
            lower = x
        else:
            upper = x - 1

N, M, K = nn()
A = nn()
B = nn()

a = []
sum_a = 0
for i in A:
    sum_a += i
    a.append(sum_a)

b = []
sum_b = 0
for i in B:
    sum_b += i
    b.append(sum_b)

#print(a, b)
ans = -1
for i in range(len(a)):
    ai = a[i]
    tmp = K - ai

    j = bisect_right(b, tmp) - 1
    if j >= len(b) or j == -1:
        continue

    bi = b[j]
    #print(i, j, a, b, ai, bi, ai + bi)   
    if i + j > ans:
        ans = i + j

if ans >= 0:
    print(ans+2)
else:
    print(0)

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]:
			if a[0]<=k:
				k-=a[0]
				count+=1
				a.pop(0)
				
			else:
				break
		else:
			if b[0]<=k:
				k-=b[0]
				count+=1
				b.pop(0)
			else:
				break
	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 = [int(n) for n in input().split()]
A = [int(n) for n in input().split()]
B = [int(n) for n in input().split()]
t = 0
ans = 0
while True:
    if len(A) and len(B):
        if A[0] < B[0]:
            t += A.pop(0)
        else:
            t += B.pop(0)
    else:
        if len(A)==0:
            t += B.pop(0)
        else:
            t += A.pop(0)
    ans += 1
    if t > K or (len(A)==0 and len(B)==0):
        break
print(ans if t <= K else ans-1)

Submission status: Wrong Answer

Solution code:
from collections import deque

N, M, K = 3, 4, 240
ARR = [60, 90, 120]
BRR = [80, 150, 80, 150]

# N, M, K = 3, 4, 730
# ARR = [60, 90, 120]
# BRR = [80, 150, 80, 150]

# N, M, K = 5, 4, 1
# ARR = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000]
# BRR = [1000000000, 1000000000, 1000000000, 1000000000]

N, M, K = 2, 5, 7
ARR = [1, 6]
BRR = [5, 1]


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


def calculate(n, m, k, arr, brr):
    q1 = deque(arr)
    q2 = deque(brr)

    total = 0
    result = 0

    while (total <= k) and (len(q1) > 0) and (len(q2) > 0):
        s1 = q1[0]
        s2 = q2[0]
        if s1 < s2:
            m = q1.popleft()
            total += m
            if total <= k:
                result += 1
        else:
            m = q2.popleft()
            total += m
            if total <= k:
                result += 1

    while (total <= k) and (len(q1) > 0) and (len(q2) == 0):
        m = q1.popleft()
        total += m
        if total <= k:
            result += 1

    while (total <= k) and (len(q1) == 0) and (len(q2) > 0):
        m = q2.popleft()
        total += m
        if total <= k:
            result += 1

    print(result)


calculate(N, M, K, ARR, BRR)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
A = [*map(int, input().split())]
B = [*map(int, input().split())]
ans = 0
a = b = 0
if k-A[a]<0 and k-B[b]<0:
    print(ans)
    exit()
while k > 0:
    if a<len(A) and b>=len(B):
        ans += 1
        # print('1 a',A[a])
        k -= A[a]
        a += 1
        if a<len(A) and k-A[a]<0:break
    elif a>=len(A) and b<len(B):
        ans += 1
        # print('2 b',B[b])
        k -= B[b]
        b += 1
        if b<len(B) and k-B[b]<0:break
    elif A[a] < B[b]:
        ans += 1
        # print('3 a',A[a])
        k -= A[a]
        a += 1
        if a<len(A) and b<len(B):
            if k-A[a]<0 and k-B[b]<0:break
        elif a>=len(A) and b>=len(B):
            break
        elif a>=len(A):
            if k-B[b]<0:break
        elif b>=len(B):
            if k-A[a]<0:break
    elif A[a] >= B[b]:
        ans += 1
        # print('4 b',B[b])
        k -= B[b]
        b += 1
        if a<len(A) and b<len(B):
            if k-A[a]<0 and k-B[b]<0:break
        elif a>=len(A) and b>=len(B):
            break
        elif a>=len(A):
            if k-B[b]<0:break
        elif b>=len(B):
            if k-A[a]<0:break
    else:
        pass
    # if len(A)==a or len(B)==b: break
print(ans)
# if len(A)==a or len(B)==b:
#     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()))

if K >= sum(A) + sum(B):
    print(N + M)

else:
    T = 0
    ans = 0
    while T < K:
        if len(A) > 0 and len(B) > 0:
            T += min(A[0],B[0])
            ans += 1
            if A[0] < B[0]:
                A.pop(0)
            else:
                B.pop(0)
        else:
            if len(A) > 0:
                T += A[0]
                A.pop(0)
                ans += 1
            elif len(B) > 0:
                T += B[0]
                B.pop(0)
                ans += 1
            else:
                break

    print(ans-1)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
from itertools import accumulate #list(accumulate(A))
'''
N, M , lim = mi()

A = li()
B = li()

A += [10**9+1]
B += [10**9+1]
ind_a = 0 
ind_b = 0

cnt = ans = 0

while True:
    if A[ind_a] > B[ind_b]:
        if cnt + B[ind_b] <= lim:
            ans += 1
            cnt += B[ind_b]
            if ind_b != M:
                ind_b += 1
        else:
            break

    elif A[ind_a] < B[ind_b]:
        if cnt + A[ind_a] <= lim:
            ans += 1
            cnt += A[ind_a]
            if ind_a != N:
                ind_a += 1
        else:
            break

    else:
        if ind_a == N and ind_b == M:
            break
        elif ind_a == N:
            if cnt + B[ind_b] <= lim:
                ans += 1
                cnt += B[ind_b]
                if ind_b != M:
                    ind_b += 1
            else:
                break
        elif ind_b == M:
            if cnt + A[ind_a] <= lim:
                ans += 1
                cnt += A[ind_a]
                if ind_a != N:
                    ind_a += 1
            else:
                break
        else:
            if A[ind_a+1] >= B[ind_b+1]:
                if cnt + B[ind_b] <= lim:
                    ans += 1
                    cnt += B[ind_b]
                    if ind_b != M:
                        ind_b += 1
                else:
                    break
            else:
                if cnt + A[ind_a] <= lim:
                    ans += 1
                    cnt += A[ind_a]
                    if ind_a != N:
                        ind_a += 1
                else:
                    break

print(ans)
'''
N, M , lim = mi()

A = li()
B = li()

A = [1] + list(accumulate(A))
B = [1] + list(accumulate(B))
ans = 0
for i in range(N+1):
    ind = bisect.bisect_right(B, max(lim-A[i], 0))
    #print(i, ind)
    if ind > 0:
        ans = max(ans, ind + i - 1)

print(ans)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int,input().split())
A = [int(x) for x in input().split()]+[10**10]
B = [int(y) for y in input().split()]+[10**10]
a = 0
b = 0
hon = 0
while K >= A[a] or K >= B[b]:
    if K >= A[a] and A[a] <= B[b]:
        K -= A[a]
        a += 1
        hon += 1
    if K >= B[b] and B[b] <= A[a]:
        K -= B[b]
        b += 1
        hon += 1
print(hon)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

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

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

  if (time > k): 
    hon=i
    break

print (hon)

Submission status: Wrong Answer

Solution code:
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]
print(ca, cb)
ans = 0
for i in range(N):
  if ca[i] <= K:
    idx = bisect.bisect_right(cb, K-ca[i])
  else:
    continue
  
  ans = max(ans, i+idx+1)


for i in range(M):
  if cb[i] <= K:
    idx = bisect.bisect_right(cb, K-cb[i])
  else:
    continue
  
  ans = max(ans, i+idx+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()))

total = 0
len_A = len(A)
len_B = len(B)
i = 0
j = 0
while True:
  a_i = A[i] if i < len_A else 1e10
  b_j = B[j] if j < len_B else 1e10
  if i >= len_A and j >= len_B:
    break
  if a_i < b_j:
    K -= float(a_i)
    i += 1
  else:
    K -= float(b_j)
    j += 1
  if K >= 0 - 1e-2:
    total += 1
  else:
    break
    
print(total)

Submission status: Wrong Answer

Solution code:
from collections import deque
def main():
    N, M, K = map(int, input().split())
    A = [int(a) for a in input().split()]
    B = [int(b) for b in input().split()]
    A = deque(A)
    B = deque(B)

    ans = 0
    tot = 0

    for i in range(len(A) + len(B)):

        if len(A) >= 1 and len(B) >= 1:
            a = A[0]
            b = B[0]

            if a < b:
                if tot + a <= K:
                    ans += 1
                    tot += A.popleft()
                else:
                    break

            elif a > b:
                if tot + b <= K:
                    ans += 1
                    tot += B.popleft()
                else:
                    break

            else:
                if tot + a <= K:
                    ans += 1
                    tot += A.popleft()
                else:
                    break

        elif len(A) == 0 and len(B) >= 1:
            b = B[0]

            if tot + b <= K:
                ans += 1
                tot += B.popleft()
            else:
                break

        elif len(A) >= 1 and len(B) == 0:
            a = A[0]

            if tot + a <= K:
                ans += 1
                tot += A.popleft()
            else:
                print(ans)
                break

        else:
            break

    print(ans)

if __name__ == "__main__":
    main()

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

ans = 0
if min(A[0],B[0]) > K:
    ans = 0
else:
    while True:
        K = K - min(A[0],B[0])
        if K < 0:
            break
        ans += 1
        if min(A[0],B[0])==A[0]:
            A.pop(0)
            if A == []:
                A.append(10**9+1)
        else:
            B.pop(0)
            if B == []:
                B.append(10**9+1)
                
print(ans)

Submission status: Wrong Answer

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

time=0
book=0

while time<=k:
    if a and b:
        time+=min(a[0], b[0])
        if a[0]<b[0]:
            a.pop(0)
        else:
            b.pop(0)
    elif b and (not a):
        time+=b[0]
        b.pop(0)
    elif a and (not b):
        time+=a[0]
        a.pop(0)
    else:
        book+=1
        break
    book+=1

print(book-1)

Submission status: Wrong Answer

Solution code:

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

time = 0
count = 0

if sum(A) + sum(B) <= K:
    print(len(A) + len(B))

while time <= K:
    if len(A) > 0 and len(B) > 0:
        a = A.pop()
        b = B.pop()

        if a < b:
            B.append(b)
            time += a
        else:
            A.append(a)
            time += b

    elif len(A) > 0:
        a = A.pop()
        time += a

    elif len(B) > 0:
        b = B.pop()
        time += b

    count += 1

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(' ')))
l=0
while (A !=[] or B != []) and K>0:
    if A==[]:
            K=K-B[0]
            B.pop(0)
            continue
    if B==[]:
            K=K-A[0]
            A.pop(0)
            continue
    if A[0]<=B[0]:
        K=K-A[0]
        A.pop(0)
    else:
        K=K-B[0]
        B.pop(0)
if A ==[] and B == []:
    print(N+M- len(A)-len(B))
else:
    print(N+M- len(A)-len(B)-1)

Submission status: Wrong Answer

Solution code:
def main():
  N,M,K=input().split()
  a=[int(x) for x in input().split()]
  b=[int(x) for x in input().split()]
  ai=0
  bi=0
  cnt=0
  count=0
  while cnt<=int(K):
    if ai>=int(N) and bi>=int(M):
      return ai+bi
    elif ai>=int(N):
      cnt+=b[bi]
      bi+=1
    elif bi>=int(M):
      cnt+=a[ai]
      ai+=1
    elif a[ai]<=b[bi]:
      cnt+=a[ai]
      ai+=1
    else:
      cnt+=b[bi]
      bi+=1
  return ai+bi-1

if __name__=='__main__':
  print(main())

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()))
len_a = len(A)
len_b = len(B)

cnt=0
while K >= 0:
  if (len_a == 0 and len_b == 0):
    break
  if ((len_a > 0) and (len_b == 0 or A[0] < B[0])):
    if A[0] > K:
      break
    K = K - A.popleft()
    cnt += 1
    len_a -= 1
  elif ((len_b > 0) and (len_a == 0 or A[0] >= B[0])):
    if B[0] > K:
      break
    K = K - B.popleft()
    cnt += 1
    len_b -= 1
print(cnt)