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 sys
import math
import numpy as np
import functools
import operator
import collections
import itertools

N,M,K = map(int, input().split())
A = list(map(int, input().split())) 
B = list(map(int, input().split())) 
ans=0
count=0
for i in range(N+M):
    
    if A[0]>B[0]:
        count+=B[0]
        B.pop(0)
        if count>K:
            print(ans)
            sys.exit()
        ans+=1
        if len(B)==0:
            break
    if A[0]<B[0]:
        count+=A[0]
        A.pop(0)
        if count>K:
            print(ans)
            sys.exit()
        ans+=1   
        if len(A)==0:
            break
if len(B)==0:
    for i in range(len(A)):
        count+=A[i]
        if count>K:
            print(ans)
            sys.exit()
        ans+=1
if len(A)==0:
    for i in range(len(B)):
        count+=B[i]
        if count>K:
            print(ans)
            sys.exit()
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ad = deque(a)
ad.append(float('inf'))
bd = deque(b)
bd.append(float('inf'))
count = 0
while True:
    k = k - min(ad[0],bd[0])
    if k < 0:
        break
    if ad[0] > bd[0]:
        if bd[0] == float('inf'):
            print(count)
            exit()
        bd.popleft()
    else:
        if ad[0] == float('inf'):
            print(count)
            exit()
        ad.popleft()
    count += 1
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()))
if sum(A)+sum(B) <= K:
  print(N+M)
else:
  a1 = 0
  b1 = 0
  S = 0
  k = 0
  while S < K:
    if a1 <N and b1<M:
      if A[a1] < B[b1]:
        S += A[a1]
        k += 1
        a1 += 1
      else:
        S += B[b1]
        k += 1
        b1 += 1
    elif a1 == N:
      S += B[b1]
      k += 1
      b1 += 1
    else:
      S += A[a1]
      k+= 1
      a1 += 1
  if S > K:
    print(k-1)
  else:
    print(k)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right

n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
asum = [0]*n
asum[0] = a[0]
b = list(map(int, input().split()))
bsum = [0]*m
bsum[0]=b[0]
for i in range(1, n):
  asum[i]=asum[i-1]+a[i]
for i in range(1, m):
  bsum[i]=bsum[i-1]+b[i]

ans = 0
for i in range(n):
  if asum[i] <= k:
    temp = i+1
    nokori = k-asum[i]
    #print("i " + str(i) + " nokori " + str(nokori))
    temp += bisect_right(bsum, nokori)
    ans = max(ans, temp)
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, count = 0, 0
while time <= k:
    if len(A) == 0 and len(B) == 0:
        break
    if len(A) > 0 and len(B) > 0:
        if A[0] < B[0]:
            time += A.pop(0)
        else:
            time += B.pop(0)
    else:
        if len(A) == 0:
            time += B.pop(0)
        else:
            time += A.pop(0)
    if time > k:
        break
    count += 1

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
A_i = 0
B_i = 0
while time < K:
    if A_i < N and B_i < M:
        if A[A_i] < B[B_i]:
            time += A[A_i]
            A_i += 1
        else:
            time += B[B_i]
            B_i += 1
    elif A_i < N and B_i >= M:
        time = A[A_i]
        A_i += 1
    elif A_i >= N and B_i < M:
        time = B[B_i]
        B_i += 1
    else:
        break

if time == K:
    print(A_i + B_i)
else:
    print(A_i + B_i -1)

Submission status: Wrong Answer

Solution code:
from collections import deque
n,m,k=[int(_) for _ in input().split()]
A=deque([int(_) for _ in input().split()])
B=deque([int(_) for _ in input().split()])
jikan=0
yomi=0
while (A or B):
    if A and B:
        if A[0]<B[0]:
            jikan+=A.popleft()
        else:
            jikan+=B.popleft()
    elif A:
        jikan+=A.popleft()
    else:
        jikan+=B.popleft()
    
    if jikan<=k:
        yomi+=1
    else:
        break
print(yomi)

Submission status: Wrong Answer

Solution code:
def main():
	from collections import deque
	n,m,k = map(int,input().split())
	a = deque(map(int,input().split()))
	b = deque(map(int,input().split()))
	ans = 0
	timer = 0
	while timer <= k-1:
		if len(a) == len(b) == 0:
			continue
		elif len(a) == 0:
			ans += 1
			timer += b.popleft()
		elif len(b) == 0:
			ans += 1
			timer += a.popleft()
		else:
			if a[0] > b[0] and timer+b[0] <= k:
				ans += 1
				timer += b.popleft()
			elif a[0] < b[0] and timer+a[0] <= k:
				ans += 1
				timer += a.popleft()
			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()))
a = 0
b = 0
ans = 0
if sum(A) + sum(B) <= K:
    print(N+M)
    exit()
A.append(10**9+1)
B.append(10**9+1)
while min(A[a],B[b]) <= K:
    if A[a] == min(A[a],B[b]):
        K -= A[a]
        a += 1
    else:
        K -= B[b]
        b += 1
    ans += 1
print(ans)

Submission status: Wrong Answer

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

import sys
import math
from decimal import Decimal, ROUND_DOWN


debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        # for line in sys.stdin:
        #     lines.append(line)
        lines.append(input())
        lines.append(input())
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    (n, m, k) = [int(e) for e in lines[0].split(' ')]
    a = [int(e) for e in lines[1].split(' ')]
    b = [int(e) for e in lines[2].split(' ')]


    return (n, m, k, a, b)


def solve(n, m, k, a, b):

    
    i = 0
    j = 0
    t = 0
    cnt = 0
    while i < n or j < m:

        if i < n and j < m:
            if a[i] < b[j]:
                t = t + a[i]
                i = i + 1
            else:
                t = t + b[j]
                j = j + 1
        elif i < n:
            t = t + a[i]
            i = i + 1
        elif j < m:
            t = t + b[j]
            j = j + 1

        if t <= k:
            cnt = cnt + 1
        else:
            break


    return cnt
    


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

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

A.append(0)
B.append(0)

ans = 0
ai = 0
bi = 0
time = k
while True:
  if time == 0 or (time < A[ai] and time < B[bi]):
    break
  
  if A[ai] <= B[bi] and ai < n:
    time -= A[ai]
    ai += 1
    ans += 1
  elif bi < m:
    time -= B[bi]
    bi += 1
    ans += 1
    
  if ai == n and bi == m:
    break

print(ans)

Submission status: Wrong Answer

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

#a = int(input())
#b = list(map(int, input().split()))
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
#s = input()
#s,t = input().split()
#a = [int(input()) for _ in range(n)]
#
#readline = sys.stdin.readline
#n,m = [int(i) for i in readline().split()]
#ab = [[int(i) for i in readline().split()] for _ in range(n)]

from collections import deque

a = deque(a)
b = deque(b)

ans = 0
time = 0

while time <= k:
    if a and b:
        tmp_a = time+a[0]
        tmp_b = time+b[0]
        if tmp_a <= k and tmp_b <= k and a[0] <= b[0]:
            time += a[0]
            a.popleft()
            ans += 1
        elif tmp_a <= k and tmp_b <= k and b[0] <= a[0]:
            time += b[0]
            b.popleft()
            ans += 1
        elif tmp_a <= k:
            time += a[0]
            a.popleft()
            ans += 1
        elif tmp_b <= k:
            time += b[0]
            b.popleft()
            ans += 1
        else:
            break
    elif a:
        tmp_a = time+a[0]
        if tmp_a <= k:
            time += a[0]
            a.popleft()
            ans += 1
        else:
            break
    elif b:
        tmp_b = time+b[0]
        if tmp_b <= k:
            time += b[0]
            b.popleft()
            ans += 1
        else:
            break
    else:
        break

print(ans)

Submission status: Wrong Answer

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

# print(n, m, k)
# print(a)
# print(b)

ans = set()
ans.add(0)
for i_n in range(1, n+1):
    if sum(a[:i_n]) > k:
        break
    for i_m in range(1, m+1):
        if sum(b[:i_m]) > k:
            break

        time_sum = sum(a[:i_n]) + sum(b[:i_m])
        if time_sum <= k:
            # print(i_n, a[:i_n], i_m, sum(b[:i_m]), k)
            ans.add(i_n + i_m)

# print(ans)

print(list(ans)[-1])

Submission status: Wrong Answer

Solution code:
#s = input()
#n = int(input())
#s,t = input().split()
#n,m = map(int,input().split())
#a = list(map(int,input().split()))
#w = [int(input()) for _ in range(N)]

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

ans = 0
ia = 0
ib = 0

while(1):
    if (ia < n) and (ib < m):
        if a[ia] < b[ia]:
            if k >= a[ia]:
                k -= a[ia]
                # print("ia={},k={}".format(ia,k))
                ans += 1
                ia += 1
            else:
                break
        else:
            if k >= b[ib]:
                k -= b[ib]
                # print("ib={},k={}".format(ib,k))
                ans += 1
                ib += 1
            else:
                break
    elif (ia < n): # b の残りなし
        if k >= a[ia]:
            k -= a[ia]
            ans += 1
            ia += 1
        else:
            break
    elif (ib < m): # a の残りなし
        if k >= b[ib]:
            k -= b[ib]
            ans += 1
            ib += 1
        else:
            break
    else: #a, b とも残りなし
        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()))

lenab=n+m #len(a)+len(b)
r=0
t=0
for ii in range(lenab):
  if n>0 and m<=0:
    print(r)
    exit()
  elif n>0 and m<=0:
    t0=a.pop(0)
    n-=1
  elif n<=0 and m>0:
    t0=b.pop(0)
    m-=1    
  else:
    if a[0]<b[0]:
      t0=a.pop(0)
      n-=1
    else:
      t0=b.pop(0)
      m-=1
#  print(ii,t,t0,a,b)
  if t+t0>k:
    print(r)
    exit()
  else:
    r+=1
    t+=t0

print(r)

Submission status: Wrong Answer

Solution code:
[n, m, k] = list(map(int, input().split()))
aList = list(map(int, input().split()))
bList = list(map(int, input().split()))

numCount = 0
while True:
    if aList and bList:
        if k >= aList[0] and k >= bList[0]:
            if aList[0] >= bList[0]:  # then read b
                k -= bList.pop(0)
                numCount += 1
            else:  # then read a
                k -= aList.pop(0)
                numCount += 1
        elif aList[0] <= k <= bList[0]:  # then read a
            k -= aList.pop(0)
            numCount += 1
        elif aList[0] >= k >= bList[0]:  # then read b
            k -= bList.pop(0)
            numCount += 1
        else:
            break
    elif aList and not bList:
        if k >= aList[0]:  # then read a
            k -= aList.pop(0)
            numCount += 1
        else:
            break
    elif bList and not aList:
        if k >= bList[0]:  # then read a
            k -= bList.pop(0)
            numCount += 1
        else:
            break
    elif not aList and not bList:
        break
print(numCount)

Submission status: Wrong Answer

Solution code:
import bisect

n,m,k = map(int,input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

a_li = [0]*(n+1)
b_li = [0]*(m+1)

for i in range(n):
    a_li[i+1] = a_li[i]+a[i]
    
for i in range(m):
    b_li[i+1] = b_li[i]+b[i]

ans = 0
#print(b_li)
#print(a_li)
for i in range(n+1):
    tmp_k = k - a_li[i]
    if tmp_k < 0:
        continue
    idx = bisect.bisect_right(b_li, tmp_k)
    #print(tmp_k,idx,idx,idx,b_li[idx-1])
    if idx <= 1:
        continue
    ans = max(ans,i+idx-1)
    #print(ans)
    #print(k,idx,b_li[idx-1])
    
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

A_que = deque(A)
B_que = deque(B)

for _ in range(N+M):
    if A_que.__len__() != 0:
        a = A_que[0]
    else:
        a = float('inf')
    if B_que.__len__() != 0:
        b = B_que[0]
    else:
        b = float('inf')
    if a >= b and K - b >= 0:
        K -= B_que.popleft()
        ans += 1
    elif b > a and K - a >= 0:
        K -= A_que.popleft()
        ans += 1
    else:
        break
print(ans)

Submission status: Wrong Answer

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

total = a+b
ans = 0

for i in range(int(n)+int(m)):
    total[i] = int(total[i])

total = sorted(total)

for i in total:
    if k - i >= 0:
        k -= i
        ans += 1
    else:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
def resolve():
    import sys
    input = sys.stdin.readline
    # 整数 1 つ
    # n = int(input())
    # 整数複数個
    n, m, k = map(int, input().split())
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

    cnt_A = 0
    cnt_B = 0
    readtime = 0

    for i in range(n+m):
        if len(A) > 0 and len(B) > 0:
            readtime += min(A[0], B[0])
            if readtime > k:
                readtime -= min(A[0], B[0])
                break
            else:
                if A[0] <= B[0]:
                    cnt_A += 1
                    del A[0]
                else:
                    cnt_B += 1
                    del B[0]

        elif len(A) == 0:
            readtime += B[0]
            if readtime > k:
                readtime -= B[0]
                break
            else:
                cnt_B += 1
                del B[0]

        else:
            readtime += A[0]
            if readtime > k:
                readtime -= A[0]
                break
            else:
                cnt_A += 1
                del A[0]

    print(cnt_A + cnt_B)


resolve()

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

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


As = list(accumulate(A))
Bs = list(accumulate(B))

ans = 0
if Bs[M-1] <= K:
    ans = max(ans, M)
idx = M-1
for i in range(N):    
    while idx != -1 and As[i] + Bs[idx] > K:
        idx -= 1
    num = i + idx + 2
    if As[i] > K:  
        num = 0
    ans = max(ans, num)

print(ans)

Submission status: Wrong Answer

Solution code:
# from pprint import pprint
# import math
# import collections

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

total = 0
t = 0
cnt = 0
while True:
    if a and b:
        if a[0] <= b[0]:
            t = a.pop(0)
            # print('read a', t)
            cnt += 1
        else:
            t = b.pop(0)
            # print('read b', t)
            cnt += 1
    elif a:
        t = a.pop(0)
        # print('read a', t)
        cnt += 1
    elif b:
        t = b.pop(0)
        # print('read b', t)
        cnt += 1
    else:
        break

    total += t

    if total > k:
        cnt -= 1
        break

print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import deque
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N,M,K = map(int, readline().split())
    A = [int(i) for i in readline().split()]
    B = [int(i) for i in readline().split()]

    books = A + B
    books.sort()

    ans = 0
    time = 0
    for t in books:
        if time + t <= K:
            time += t
            ans += 1
        else:
            break

    print(ans)
       


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N, M, K = (int(i) for i in input().split())
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    from itertools import accumulate
    sA = list(accumulate([0] + A))
    sB = list(accumulate([0] + B))
    canA, canB = -1, -1
    for i, a in enumerate(sA):
        if K < a:
            break
        canA = i
    for i, a in enumerate(sB):
        if K < a:
            break
        canB = i
    t = sA[canA] + sB[canB]
    while K < t:
        if canA > 0 and A[canA-1] > B[canB-1]:
            t -= A[canA-1]
            canA -= 1
        elif canB > 0 and A[canA-1] < B[canB-1]:
            t -= B[canB-1]
            canB -= 1
        elif canA < canB:
            t -= A[canA-1]
            canA -= 1
        elif canB < canA:
            t -= B[canB-1]
            canB -= 1
        else:
            t -= B[canB-1]
            canB -= 1
    print(canA + canB)


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

count = 0
timecount = 0

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

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()))
i,j=0,0
for l in range(n+m):
    if i==n:
        if j<m:
            x=b[j]
        else:
            print(l)
            exit()
    elif j==m:
        if i<n:
            x=a[i]
        else:
            print(l)
            exit()     
    else:  
        x=min(a[i],b[j])
    k-=x
    if k<0:
        print(l)
        exit()
    if k==0:
        print(l+1)
        exit()
    if i<n and x==a[i]:
        i+=1
    elif j<m and x==b[j]:
        j+=1
print(n+m)

Submission status: Wrong Answer

Solution code:
n,m,k = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
brr = [int(x) for x in input().split()]

time = 0
i,j = 0,0
res = 0
while i < n or j < m:
    if i >= n:
        first = 98556985985989859858
    else:
        first = arr[i]
    if j >= m:
        second = 98556985985989859858
    else:
        second = brr[j]
    # print(str(i) +'  '+str(j) +'  '+str(time))
    read = min(first,second)
    if (i < n and read == arr[i]):
        if time + arr[i] <= k:
            time += arr[i]
            i += 1
            res += 1
        else:
            break
    else:
        if time + brr[j] <= k:
            res += 1
            time += brr[j]
            j += 1
        else:
            break


print(res)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
INF = 10**9+7
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
a.append(INF)
b.append(INF)
ans = 0
posa = 0
posb = 0
for i in range(n+m):
    if a[posa] > b[posb]:
        k -= b[posb]
        posb += 1
        ans += 1
    else:
        k -= a[posa]
        posa += 1
        ans += 1
        
    if k < 0:
        ans -= 1
        break
    elif k == 0:
        break
print(ans)

Submission status: Wrong Answer

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

As = list(map(int, input().split()))
Bs = list(map(int, input().split()))

i = 0
j = 0
T = 0
cnt = 0

while T <= K:
  if i >= N and j >= M:
    break
  elif i >= N:
    T += Bs[j]
    j += 1
  elif j >= M:
    T += As[i]
    i += 1
  else:
    if As[i] > Bs[j]:
      T += Bs[j]
      j += 1
    elif As[i] < Bs[j]:
      T += As[i]
      i += 1
    else:
      if i+1 >= N or j+1 >= M:
        T += As[i]
        i += 1
      elif As[i+1] >= Bs[j+1]:
        T += Bs[j]
        j += 1
      else:
        T += As[i]
        i += 1
  cnt += 1
  
if T > K:
  print(cnt-1)
else:
  print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**8)
n, m, k = map(int, input().split())
a = list(map(int, input().split())) + [10 ** 10]
b = list(map(int, input().split())) + [10 ** 10]


def dfs(ai, bi, time, finished=False):
    if finished:
        return ai + bi

    if ai == n-1 and bi == n-1:
        return ai + bi

    if time >= a[ai]:
        ret1 = dfs(ai + 1, bi, time - a[ai])
    else:
        ret1 = dfs(ai, bi, time, finished=True)

    if time >= b[bi]:
        ret2 = dfs(ai, bi + 1, time - b[bi])
    else:
        ret2 = dfs(ai, bi, time, finished=True)

    return max(ret1, ret2)


print(dfs(0, 0, k))

Submission status: Wrong Answer

Solution code:
N,M,K = map(int, input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
A.append(10**9+1)
B.append(10**9+1)
t=0
a=0
while t<=K:
  if A[0] < B[0]:
    t+=A[0]
    if t>K:
      print(a)
      exit()
    A.pop(0)
    a+=1
  elif A[0] >= B[0]:
    t+=B[0]
    if t>K:
      print(a)
      exit()
    B.pop(0)
    a+=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()))
t = 0
for i in range(len(A)+len(B)+1):
    if len(A) == 0 and len(B) == 0:
        break
    if len(A) == 0:
        t += B.pop(0)
    elif len(B) == 0:
        t += A.pop(0)
    elif A[0] < B[0]:
        t += A.pop(0)
    else:
        t += B.pop(0)
    if t > K:
        break
print(i)

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()]
from collections import deque
da = deque(a)
db = deque(b)
aa = da.popleft()
bb = db.popleft()
count = 0
for i in range(N+M):
    if aa <= bb:
        if K - aa < 0 :
            break
        count += 1
        K -= aa
        if da:
            aa = da.popleft()
        else:
            aa = 10**11
    else:
        if K - bb < 0 :
            break
        count += 1
        K -= bb
        if db:
            bb = db.popleft()
        else:
            bb = 10**11
print(count)

Submission status: Wrong Answer

Solution code:
# import sys
# import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,\
#     combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
# mod = 998244353
INF = 1<<50

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

def main():
    n,m,k = readInt()
    a = readInt()
    b = readInt()
    t = 0
    i = 0
    j = 0
    ans = 0
    while t<k:
        if i==n and j==m:
            break
        elif i==n:
            if t+b[j]<=k:
                t += b[j]
                j += 1
                ans += 1
            else:
                break
        elif j==m:
            if t+a[i]<=k:
                t += a[i]
                i += 1
                ans += 1
            else:
                break
        else:
            if t+a[i]>k and t+b[j]>k:
                break
            else:
                if a[i]<b[j]:
                    t += a[i]
                    i += 1
                else:
                    t += b[j]
                    j += 1
                ans += 1
    print(ans)
    return

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()))
countA=0
countB=0
shoyou=K
tot=0
for i in range(10**5):
    if shoyou>=0 and countA<N and countB<M and A[countA]>=B[countB]:
        shoyou-=B[countB]
        tot+=1
        countB+=1
    elif shoyou>=0 and countA<N and countB<M and A[countA]<B[countB]:
        shoyou-=A[countA]
        tot+=1
        countA+=1
    elif shoyou>=0 and countA<N and countB>=M:
        shoyou-=A[countA]
        tot+=1
        countA+=1
    elif shoyou>=0 and countA>=N and countB<M:
        shoyou-=B[countB]
        tot+=1
        countB+=1
    elif shoyou>=0 and countA>=N and countB>=M:
        tot+=1
        break
    elif shoyou<0:
        break
print(tot-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()))

time = 0
count = 0
while len(A) or len(B):
    if len(A) and len(B):
        desk = A if A[0] < B[0] else B
    elif len(A):
        desk = A
    elif len(B):
        desk = B
    time += desk.pop(0)

    if time > K:
        break
    else:
        count += 1

print(count)

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()))
INF = 10**10
ans = 0
now = 0

while now <= K:
    if A:
        a = A[0]
    else:
        a = INF
    if B:
        b = B[0]
    else:
        b = INF
    now += min(a, b)
    ans += 1
    if now >= INF:
        break
    if a >= b:
        B.popleft()
    elif b > a:
        A.popleft()
    
print(ans-1)

Submission status: Wrong Answer

Solution code:
def iteraccumulate(l):
    from itertools import accumulate
    return list(accumulate(l))


def resolve():
    from bisect import bisect_right
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    aa = [0] + iteraccumulate(a)
    bb = iteraccumulate(b)
    ans = 0
    for index, i in enumerate(aa):
        j = bisect_right(bb, k - i)
        if i + bb[j - 1] <= k:
            ans = max(ans, index + j)
    print(ans)


if __name__ == '__main__':
    resolve()

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
acount,bcount=0,0

for i in range(n+m+1):
  if a[0]<=b[0]:
    if k-a[0]>=0:
      count+=1
      acount+=1
      k-=a[0]
      del a[0]
      
      if acount==n:
        a.append(1000000000000)
        
    else:
      break
      
  else:
    if k-b[0]>=0:
      count+=1
      bcount+=1
      k-=b[0]
      del b[0]
      
      if bcount==m:
        b.append(1000000000000)
      
    else:
      break
      
print(count)

Submission status: Wrong Answer

Solution code:
import sys
import bisect
import itertools
import collections
import fractions
import heapq
import math
from operator import mul
from functools import reduce
from functools import lru_cache


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    N, M, K = map(int, readline().split())
    A = list(map(int, readline().split()))
    B = list(map(int, readline().split()))


    nowtime = 0
    acount = 0
    bcount = 0
    empty = False
    while nowtime <= K:
        if acount < N and bcount < M:
            if A[acount] < B[bcount]:
                nowtime += A[acount]
                acount += 1
            else:
                nowtime += B[bcount]
                bcount += 1
        elif acount == N and bcount == M:
            acount += 1
            break
        else:
            if acount == N:
                nowtime += B[bcount]
                bcount += 1


    print(acount+bcount-1)



if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7


def inp():
    '''
    一つの整数
    '''
    return int(input())


def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


def str_inp():
    '''
    文字列をリストとして読み込む
    '''
    return list(input()[:-1])


n, m, k = inpl()
a = inpl()
b = inpl()
tmp = 0
for i in range(len(a)):
    tmp += a[i]
    a[i] = tmp
tmp = 0
for i in range(len(b)):
    tmp += b[i]
    b[i] = tmp
ans = 0
a_start = bisect.bisect_right(a, k)
for a_amount in range(a_start, -1, -1):
    new_k = k - a[a_amount - 1]
    b_amount = bisect.bisect_right(b, new_k)
    ans = max(ans, a_amount + b_amount)
print(ans)