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

cut = 0
s = 0

D =[]
F =[]

for i in range(10 ** 9):
    if A[0] <= B[0]:
        s = s + A[0]
        if s > K:
            break
        elif s < K:
            del A[0]
            cut += 1
            if len(A)== 0:
                D.append(1)
                break
        elif s == K:
            cut += 1
            break
    else:
        s = s + B[0]
        if s > K:
            break
        elif s < K:
            del B[0]
            cut += 1
            if len(B)== 0:
                F.append(1)
                break
        elif s == K:
            cut += 1
            break


if len(D) == 1:
    for j in range(100):
        s = s + B[0]
        if s > K:
            break
        elif s < K:
            del B[0]
            cut += 1
        elif s == K:
            cut += 1
            break

if len(F) == 1:
    for jj in range(100):
        s = s + A[0]
        if s > K:
            break
        elif s < K:
            del A[0]
            cut += 1
        elif s == K:
            cut += 1
            break
              
        
print(cut)

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_sum=[sum(A[:_+1]) for _ in range(len(A))]
B_sum=[sum(B[:_+1]) for _ in range(len(B))]

ans=0

for i in range(len(A_sum)):
	for h in range(len(B_sum)):
		if A_sum[i]+B_sum[h]>K and A_sum[i]+B_sum[h-1]<=K and h>0:
			ans=max(ans,i+1+h)

print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# 日本語を入力できるようにするために上記一文が必要


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

read_time = 0
read_count = 0
while read_time < k:
        if not a_list and not b_list:
                read_count += 1
                break
        elif not a_list and b_list:
                read_count += 1
                read_time += b_list[0]
                b_list.remove( b_list[0])
        elif a_list and not b_list:
                read_count += 1
                read_time += a_list[0]
                a_list.remove( a_list[0])
        elif a_list[0] <= b_list[0]:
                read_time += a_list[0]
                a_list.remove( a_list[0])
                read_count += 1
        else:
                read_time += b_list[0]
                b_list.remove( b_list[0])
                read_count += 1

if read_time > k:
        print(read_count - 1)
else:
        print(read_count)

Submission status: Wrong Answer

Solution code:
NMK=input().split(" ")
N=int(NMK[0])
M=int(NMK[1])
K=int(NMK[2])

def list2int(List):
    out=[]
    for i in range(len(List)):
        out.append(int(List[i]))
    return out

A=list2int(input().split(" "))
B=list2int(input().split(" "))

a=[0]
b=[0]
for i in range(N):
    a.append(a[i]+A[i])
for i in range(M):
    b.append(b[i]+B[i])   

time=0
A_idx=0
B_idx=0
cnt=0
while(True):
    if(A_idx<len(A) and B_idx<len(B)):
        if(A[A_idx]<B[B_idx]):
            time+=A[A_idx]
            A_idx+=1
        else:
            time+=B[B_idx]
            B_idx+=1
    elif(A_idx>=len(A) and B_idx<len(B)):
        time+=B[B_idx]
        B_idx+=1
    elif(B_idx>=len(B) and A_idx<len(A)):
        time+=A[A_idx]
        A_idx+=1
    else:
        break
    if(time>K):
        break
    else:
        cnt+=1

print(cnt)

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

sumb = sum(b)
nb = m

while sumb > k:
	sumb -= b[nb-1]
	nb -= 1

na = 0
while sumb <= k and na < n:
	if sumb + a[na] > k:
		if nb > 0:
			if sumb - b[nb-1] + a[na] > k:
				break
			sumb -= b[nb-1]
			sumb += a[na]
			nb -= 1
			na += 1
		else:
			break
	else:
		sumb += a[na]
		na += 1
print (na+nb)

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

sa = []
i = 0
sa.append(0)
while i < n:
    sa.append(sa[-1] + a[i])
    i += 1
    if sa[-1] > k:
        sa.pop(-1)
        break

#print(sa)
sb = []
i = 0
sb.append(0)
while i < m:
    sb.append(sb[-1] + b[i])
    i += 1
    if sb[-1] > k:
        sb.pop(-1)
        break
#print(sb)

#max = -1
ans = 0
for i in range(1,len(sa)):
    for j in range(1,len(sb)):
        x = sa[i] + sb[j]
        if x > k:
            break
        
        if x <= k:
            ans = max(ans,i + j)

print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int,input().split())
tmpA = list(map(int,input().split()))
tmpB = list(map(int,input().split()))
A = [tmpA[0]] if tmpA[0] < k else []
B = [tmpB[0]] if tmpB[0] < k else []
# 読むのにかかる時間の累計和のリスト
if A:
    for i in range(1, n):
        tmp = A[i-1] + tmpA[i]
        if tmp > k:
            break
        else:
            A.append(tmp)
if B:
    for i in range(1, m):
        tmp = B[i-1] + tmpB[i]
        if tmp > k:
            break
        else:
            B.append(tmp)


while True:
    if A == [] or B == [] or A[-1] + B[-1] <= k:
        break
    if A[-1] > B[-1]:
        A.pop()
    else:
        B.pop()
print(len(A) + len(B))

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

a = [0]
b = [0]
for i in range(len(A)):
    a.append(a[i] + A[i])

for i in range(len(B)):
    b.append(b[i] + B[i])


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

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

    start_idx = max(list(ans)[-1] - i_n, 0)
    # print('start_idx', start_idx)
    for i_m in range(start_idx+1, m+1):
        if a[i_n] + b[i_m] > k:
            break

        time_sum = a[i_n] + b[i_m]
        # print(i_n, a[:i_n], i_m, b[:i_m], time_sum, k)
        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:
import sys
from itertools import accumulate

def Main():
    n,m,k = map(int,sys.stdin.readline().rstrip().split())
    a = list(accumulate(map(int,sys.stdin.readline().rstrip().split())))
    b = list(map(int,sys.stdin.readline().rstrip().split()))

    ans = 0
    for i in range(n):
        item = a[i]
        if k<item:  break
        c = i+1
        for jtem in b:
            if k<item+jtem:
                break
            item += jtem
            c += 1
        ans = max(ans,c)
    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()))

A_sum = []
a_sum = 0
for a in A:
    a_sum += a
    A_sum.append(a_sum)

B_sum = []
b_sum = 0
for b in B:
    b_sum += b
    B_sum.append(b_sum)

import bisect

max_count = 0
for idx, a_sum in enumerate(A_sum):
    if a_sum > K:
        break
    b_count = bisect.bisect_right(B_sum, K - a_sum)
    if max_count < idx+1 + b_count:
        max_count = idx+1 + b_count
    else:
        break
print(max_count)

Submission status: Wrong Answer

Solution code:
import itertools
import bisect

def main():
    N, M, K = [int(x) for x in input().split()]
    A = list(itertools.accumulate(int(x) for x in input().split()))
    B = list(itertools.accumulate(int(x) for x in input().split()))

    if A[-1] + B[-1] <= K:
        print(N+M)
        return
    ans = bisect.bisect_right(B, K)  # use B only
    for i in range(len(A)-1, -1, -1):
        target = K - A[i]
        j = bisect.bisect_right(B, target)
        ans = max(ans, i+j+1)
    print(ans)
 
 
if __name__ == '__main__':
    import sys
    sys.setrecursionlimit(10000)
    main()

Submission status: Wrong Answer

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

a_time = []
for i in range(len(a)):
  if i == 0:
    a_time.append(a[i])
  else:
    if a_time[i-1] + a[i] > k:
      break
    else:
      a_time.append(a_time[i-1] + a[i])

b_time = []
for i in range(len(b)):
  if i == 0:
    b_time.append(b[i])
  else:
    if b_time[i-1] + b[i] > k:
      break
    else:
      b_time.append(b_time[i-1] + b[i])

b_time.reverse()
cnt = 0
best_j = 0
for i in range(len(a_time)):
  k_dumy = k - a_time[i]
  for j in range(best_j,len(b_time)):
    if b_time[j] <= k_dumy:
      cnt = max(cnt, i+1 + len(b_time)-j)
      best_j = j
      break

print(cnt)

Submission status: Wrong Answer

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

import sys
import math
from decimal import Decimal, ROUND_DOWN
from collections import deque

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

    aa = deque(a)
    bb = deque(b)
    ee = []
    m = int(10**9) + 1
    while aa and bb:
        if aa[0] < bb[0]:
            ee.append(aa.popleft())
        else:
            ee.append(bb.popleft())

    while aa:
        ee.append(aa.popleft())

    while bb:
        ee.append(bb.popleft())

    if debug:
        log("ee=%s" % ee)


    t = 0
    cnt = 0
    for f in ee:
        t = t + f
        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:
#!/usr/bin/env python3
import sys
from itertools import accumulate
import numba
import numpy as np


def debug(*x):
    print(*x)


@numba.njit
def solve(N, M, K, sA, sB):
    "void()"

    last_can_read = 0
    for i in range(N):
        for j in range(M):
            if sA[i] + sB[j] <= K:
                if last_can_read < i + j:
                    last_can_read = i + j
            else:
                break

    print(last_can_read)


def main():
    N, M, K = map(int, input().split())

    AS = list(map(int, input().split()))
    BS = list(map(int, input().split()))

    sA = np.array([0] + list(accumulate(AS)))
    sB = np.array([0] + list(accumulate(BS)))
    # debug("s:sA,sB", sA, sB)
    solve(N, M, K, sA, sB)


def _test():
    """
    >>> 
    >>> main()
    """
    import doctest
    as_input('''
    3 4 240
    60 90 120
    80 150 80 150
    ''')
    main()
    doctest.testmod()


def as_input(s):
    "use in test, use given string as input file"
    import io
    global read, input
    f = io.StringIO(s.strip())
    input = f.readline
    read = f.read


USE_NUMBA = False
if (USE_NUMBA and sys.argv[-1] == 'ONLINE_JUDGE') or sys.argv[-1] == '-c':
    print("compiling")
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('solve', solve.__doc__.strip().split()[0])(solve)
    cc.compile()
    exit()
else:
    input = sys.stdin.buffer.readline
    read = sys.stdin.buffer.read

    if (USE_NUMBA and sys.argv[-1] != '-p') or sys.argv[-1] == "--numba":
        # -p: pure python mode
        # if not -p, import compiled module
        from my_module import solve  # pylint: disable=all
    elif sys.argv[-1] == "-t":
        _test()
        sys.exit()
    elif sys.argv[-1] != '-p' and len(sys.argv) == 2:
        # input given as file
        input_as_file = open(sys.argv[1])
        input = input_as_file.buffer.readline
        read = input_as_file.buffer.read

    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin
from bisect import bisect
input = stdin.readline

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

for i in range(1, N):
    A[i] += A[i - 1]

for i in range(1, M):
    B[i] += B[i - 1]

ans = 0

for i, b in enumerate(B):
    time = K - b
    if time < 0:
        break
    cnt = i + 1
    if time != 0:
        tmp = bisect(A, time)
        cnt += tmp
    ans = max(ans, cnt)

print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = 0
b = 0
ans = 0
sumA = 0
sumB = 0
for i in range(len(A)):
  sumA =sumA +A[i]
  if sumA <= k:
    a += 1
  else:
    break

for i in range(len(B)):
  sumB =sumB +B[i]
  if sumB <= k:
    b += 1
  else:
    break
#print(a)
#print(b)
ab = a+b
su = sum(A[0:a]) + sum(B[0:b])
if su <= k:
  print(ab)
else:
  for i in range(max(a,b)):
    if a==0 or b==0:
      break
    ans += 1
    if A[a-1] >= B[b-1]:
      if su - A[a-1] <= k:
        break
      else:
        a -=1
    else:
      if su - B[b-1] <= k:
        break
      else:
        b -=1   
  print(ab-ans)

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

sa = []
i = 0
sa.append(0)
while i < n:
    sa.append(sa[-1] + a[i])
    i += 1
    if sa[-1] > k:
        sa.pop(-1)
        break

#print(sa)
sb = []
i = 0
sb.append(0)
while i < m:
    sb.append(sb[-1] + b[i])
    i += 1
    if sb[-1] > k:
        sb.pop(-1)
        break
#print(sb)

#max = -1
ans = 0
for i in range(1,len(sa)):
    for j in range(1,len(sb)):
        x = sa[i] + sb[j]
        if x > k:
            j = len(sb) + 1
        
        if x <= k:
            if i + j > ans:
                ans = i + j
                #print(ans)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda: readline().rstrip() # input string
ni = lambda: int(readline().rstrip()) # input int
nm = lambda: map(int, readline().split()) # input multiple int 
nl = lambda: list(map(int, readline().split())) # input multiple int to list

n, m, k = nm()
a = nl()
b = nl()
sum_a = [0]
sum_b = [0]
for i in range(n):
    sum_a.append(sum_a[i] + a[i])
for i in range(m):
    sum_b.append(sum_b[i] + b[i])
ans = 0
j = m
for i in range(n+1):
    if sum_a[i] >= k:
        break
    while sum_b[j] > k - sum_a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# import numpy as np
sys.setrecursionlimit(int(pow(10,6)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("out.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]

# @lru_cache(None)
t=1
# t=int(input())
for _ in range(t):
    n,m,k=l()
    A=l()
    B=l()
    i=0
    j=0
    B=A[::-1]+B
    pref=[0 for i in range(n+m+1)]
    for i in range(n+m):
        pref[i+1]=pref[i]+B[i]
    ans=0
    for i in range(n+1):
        x=br(pref,pref[i]+k)
        if i<n and x<n-1:
            continue
        ans=max(ans,x-i-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()))
pa = 0
pb = 0
suma = 0
cost = 0
ans = [0]*N
while True:
	cost += A[pa]
	if cost > K:
		cost -= A[pa]
		pa -= 1
		break;
	pa += 1
	if pa >= N:
		pa -= 1
		break;
while True:
	cost += B[pb]
	if cost > K:
		cost -= B[pb]
		pb -= 1
		break;
	pb += 1
	if pb >= M:
		pb -= 1
		break;
ans[pa] = pa+pb+2
pa -= 1
while pa >= 0:
	cost -= A[pa+1]
	pb += 1
	while pb < M:
		cost += B[pb]
		if cost > K:
			cost -= B[pb]
			break;
		pb += 1
	pb -= 1
	ans[pa] = pa+pb+2
	pa -= 1
for i in range(N):
	suma = max(suma,ans[i])
print(suma)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0
aindex=n+1
bindex=m+1
acumsum = [0]
bcumsum = [0]

ab =0
for aa in range(n):
  ab += a[aa]
  acumsum.append(ab)# = ab
  if ab>k:
    aindex= aa
    break

ab =0
for bb in range(m):
  ab += b[bb]
  bcumsum.append(ab)
  if ab>k:
    bindex= bb
    break

# print(acumsum,bcumsum)
from bisect import bisect_left
for i in range(aindex):
  j = bisect_left(bcumsum, k-acumsum[i])
  # print(i,j)
  ans = max(ans, i+max(j,n))
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
a = [0]+list(map(int,input().split()))
b = [0]+list(map(int,input().split()))
s = [0]*(n+1)
t = [0]*(m+1)
p = m-1
q = n-1
x = 0
for i in range(n+1):
    s[i] += x + a[i]
    x = s[i]
x = 0
for i in range(m+1):
    t[i] += x + b[i]
    x = t[i]
#print(s,t)
x = 1
#while(1):
for i in range(30):
    f = 0
    #print(x)
    for j in range(x+1):
        if(m>=x-j):
            if(n >= j):
                if(s[j]+t[x-j] <= k):
                    #print(j,x-j)
                    f = 1
                    break
            else:
                break
    if(f == 0):
        break
    x += 1
print(x-1)

Submission status: Wrong Answer

Solution code:
buf = input().split(" ")
N = int(buf[0])
M = int(buf[1])
K = int(buf[2])

A = input().split(" ")
for i in range(N):
  A[i] = int(A[i])
B = input().split(" ")
for i in range(M):
  B[i] = int(B[i])

read_time = 0
while True:
  read_time = sum(A) + sum(B)
  if read_time > K:
    if len(A) > 0 and len(B) > 0:
      if A[-1] > B[-1]:
        del A[-1]
      else:
        del B[-1]
    elif len(A) == 0 and len(B) > 0:
      del B[-1]
    elif len(B) == 0 and len(A) > 0:
      del A[-1]
  else:
    break

print(len(A)+len(B))

Submission status: Wrong Answer

Solution code:
NMK = input().split()
A = input().split()
B = input().split()
NMK = [int(i) for i in NMK]
A = [int(i) for i in A]
B = [int(i) for i in B]
count = 0
time = NMK[2]
while True:  
  if (time < A[0]) and (time < B[0]):
    break
  if A[0] <= B[0]:
    time -= A.pop(0)
    count += 1
  else:
    time -= B.pop(0)
    count += 1
  if A == []:
    A.append(10**10)
  if B == []:
    B.append(10**10)
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()))
cumsum_a = [0]*(n+1)
cumsum_b = [0]*(m+1)
ai = 0
bi = 0
for i in range(1, n+1):
    cumsum_a[i] = cumsum_a[i-1] + a[i-1]
    ai = i
    if cumsum_a[i] > k:
        ai = i-1
        break
for i in range(1, m+1):
    cumsum_b[i] = cumsum_b[i - 1] + b[i-1]
    bi = i
    if cumsum_b[i] > k:
        bi = i-1
        break

ans = 0
sj = 0
for i in range(ai+1):
    for j in range(bi, 0, -1):
        if cumsum_a[i] + cumsum_b[j] <= k:
            ans = max(ans, i + j)
            bi = j
            break

print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from bisect import bisect

N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A_ = list(accumulate(A))
B_ = list(accumulate(B))
left = 0
right = bisect(A_, K)
if right == 0:
    print(0)
    exit()
b = bisect(B_, K-A_[right-1])
while right - left > 1:
    mid = (right+left)//2
    b_ = bisect(B_, K-A_[mid-1])
    if right - mid < b_ - b:
        right = mid
    else:
        left = mid
ans_l = left + bisect(B_, K-A_[left-1])
ans_r = right + bisect(B_, K-A_[right-1])
print(max(ans_l, ans_r))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(read())


def ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from functools import reduce
from math import gcd


def lcm(a, b):
    # 最小公倍数
    g = gcd(a, b)
    return a // g * b


class cumsum1d:  # 一次元累積和クラス
    def __init__(self, ls: list):
        '''
        1次元リストを受け取る
        '''
        from itertools import accumulate
        self.ls_accum = [0] + list(accumulate(ls))

    def total(self, i, j):
        # もとの配列lsにおける[i,j)の中合計
        return self.ls_accum[j] - self.ls_accum[i]


def two_pointers(ls: list):
    '''すべてのlに対して、条件is_okをみたすls[l:r]の中で
    r - lが最大になるような(l,r)の集合を返す'''
    n_ls = len(ls)
    ret = []

    def append(r, pre_states):
        '''状態にls[r]を考慮して更新する'''
        # 問題によって自分で定義
        return pre_states + ls[r]
        # 掛け算の例 return pre_state*ls[r]

    def pop(l, pre_states):
        '''状態からls[l]を抜く更新をする'''
        # 問題によって自分で定義
        # 掛け算の例 return pre_state//ls[l]
        return pre_states - ls[l]

    def is_ok(r, pre_states):
        # 問題によって自分で定義
        states = append(r, pre_states)
        # 114以下の最長の範囲が知りたい例 return states<=114
        return states <= K

    r = 0
    states = 0
    for l in range(n_ls):
        while r < n_ls and is_ok(r, states):
            # 更新式
            states = append(r, states)
            r += 1
        ret.append((l, r))
        # 抜けるときの更新
        states = pop(l, states)
    return ret


# K冊の組み合わせを試せば良い
# 合計は累積和で高速化
N, M, K = ints()
A = ints()
B = ints()
AB = list(reversed(A)) + B
# AB_cum = cumsum1d(AB)

ans = 0
for l, r in two_pointers(AB):
    if l <= N - 1 and N <= r + 1:
        ans = max(ans, r - l)
print(ans)

Submission status: Wrong Answer

Solution code:
NMK = input().split()
A = input().split()
B = input().split()
NMK = [int(i) for i in NMK]
A = [int(i) for i in A]
B = [int(i) for i in B]
count = 0
time = NMK[2]
while True:  
  if (time < A[0]) and (time < B[0]):
    break
  if A[0] <= B[0]:
    time -= A.pop(0)
    count += 1
    print('A')
  else:
    time -= B.pop(0)
    count += 1
    print('B')
  if A == []:
    A.append(10**10)
  if B == []:
    B.append(10**10)
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()))
import itertools
A_cs = list(itertools.accumulate(A))
B_cs = list(itertools.accumulate(B))

total = 0
for i in range(len(A_cs)):
    for j in range(len(B_cs)):
        if A_cs[i] + B_cs[j] <= K:
            if total < i + j:
                total = i + j

print(total)

Submission status: Wrong Answer

Solution code:
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# import numpy as np
sys.setrecursionlimit(int(pow(10,6)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("out.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]

# @lru_cache(None)
t=1
# t=int(input())
for _ in range(t):
    n,m,k=l()
    A=l()
    B=l()
    i=0
    j=0
    B=A[::-1]+B
    pref=[0 for i in range(n+m+1)]
    for i in range(n+m):
        pref[i+1]=pref[i]+B[i]
    ans=0
    for i in range(n+1):
        x=bl(pref,pref[i]+k)
        if x<n-1:
            continue
        ans=max(ans,x-i-1)
    print(ans)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
As = [int(i) for i in input().split()]
Bs = [int(i) for i in input().split()]

for i in range(1, min(N,M)):
  As[i] = As[i] + As[i-1]
  Bs[i] = Bs[i] + Bs[i-1]

if N > M:
  for i in range(M,N):
    As[i] = As[i] + As[i-1]
elif M>N:
  for i in range(N, M):
    Bs[i] = Bs[i] + Bs[i-1]

import numpy as np
As = np.array(As)
Bs = np.array(Bs)
Bs = Bs[Bs<=K]

cnt = 0
for i,B in enumerate(Bs):
  p = len(As[(As+B)<=K])
  if cnt < i+p+1:
    cnt = i+p+1
print(cnt)

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()))
 
T_A = [0, A[0]]
T_B = [0, B[0]]
for i in range(1, N):
  T_A.append(T_A[i] + A[i])
for j in range(1, M):
  T_B.append(T_B[j] + B[j])
      
book = 0
j = M
for i in range(len(T_A)):
  while 1:
    if K < T_A[i] + T_B[j]:
      break
    else:
      if i + j  > book:
        book = i + j
        break
      else:
        break
    
print(book)

Submission status: Wrong Answer

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

from collections import deque

an = list(map(int, input().split()))

bn = list(map(int, input().split()))

accum_a = [0]
accum_b = [0]


for a_i in range(0,len(an)):


    sumCandidate = accum_a[-1] + an[a_i]
    if sumCandidate > k:
        break
    accum_a.append(sumCandidate)

for b_i in range(0,len(bn)):
    i_ = accum_b[-1] + bn[b_i]
    if i_ > k:
        break
    accum_b.append(i_)


def Find(a, b, k1):
    if a[-1] + b[-1] <= k1:
        return len(a) - 1 + len(b) - 1

    if len(a) > len(b):
        rest = k1 - a[-1]
        for i in range(len(b)):
            if rest <= b[-i]:
                return len(a) - 1 + len(b) - 1 - i

    if len(b) > len(a):
        rest = k1 - b[-1]
        for i in range(len(a)):
            if rest <= a[-i]:
                return len(b) - 1 + len(a) - 1 - i

    if a[-1] > b[-1]:
        rest = k1 - b[-1]
        return Find(a[0:len(a)-1], b, rest)

    rest = k1 - a[-1]
    return Find(a,b[0:len(b)-1],rest)

print(Find(accum_a, accum_b, k))