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

Solution code:
import sys
import itertools
import bisect

sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

A_acc = list(itertools.accumulate(A))
B_acc = list(itertools.accumulate(B))

all_a = bisect.bisect_right(A_acc, K)
all_b = bisect.bisect_right(B_acc, K)

ans = max(all_a, all_b)

for i in range(N):
    rest = K - A_acc[i]

    if rest <= 0:
        break

    b = bisect.bisect_right(B_acc, rest)

    ans = max(ans, i + b + 1)

print(ans)

Submission status: Accepted

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

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

ans = bisect.bisect_right(B, K)
for i in range(N):
    if A[i] > K:
        break
    if K-A[i] < B[0]:
        ans = max(ans, i+1)
        continue
    j = bisect.bisect_right(B, K-A[i])
    ans = max(ans, i+j+1)

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n,m,k = map(int,readline().split())
*a, = map(int,readline().split())
*b, = map(int,readline().split())

from itertools import accumulate

a = list(accumulate(a))
b = list(accumulate([0]+b))

from bisect import bisect_right

ans = 0
for i,bi in enumerate(b):
    if bi > k: break
    r = i + bisect_right(a,k-bi)
    ans = max(ans,r)


print(ans)

Submission status: Accepted

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()]
sA = [0]*(N+1)
sB = [0]*(M+1)
for i in range(N):
    sA[i+1] = sA[i] + A[i]
for i in range(M):
    sB[i+1] = sB[i] + B[i]

res = 0
for i in range(N+1):
    Aread = sA[i]
    if Aread > K:
        break
    moku = K - Aread
    ok = 0
    ng = M+1
    while ng - ok > 1:
        mid = (ng+ok)//2
        if sB[mid] > moku:
            ng = mid
        else:
            ok = mid
    res = max(res, i+ok)
print(res)

Submission status: Accepted

Solution code:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
cuma = [0]
for a in A:
    cuma.append(cuma[-1] + a)

cumb = [0]
for b in B:
    cumb.append(cumb[-1] + b)

ans = 0
from bisect import bisect
for i,ca in enumerate(cuma):
    if ca > K: break
    t = K - ca
    j = bisect(cumb, t)
    ans = max(ans, i+j-1)
print(ans)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M, K = MAP()
A = [0]+LIST()
B = LIST()

A = list(accumulate(A))
B = list(accumulate(B))
ans = 0
for i in range(N+1):  # Aの上からi冊読む
    left = K-A[i]
    if left < 0:
        continue
    ans = max(ans, i+bisect(B, left))
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, M, K, A, B):
    from itertools import accumulate
    sa = [0] + list(accumulate(A))
    sb = [0] + list(accumulate(B))

    ans = 0
    for n, a in enumerate(sa):
        if a > K:
            continue
        m = bisect.bisect_right(sb, K-a) - 1
        ans = max(ans, n+m)
    return ans


def main():
    N, M, K = read_int_n()
    A = read_int_n()
    B = read_int_n()
    print(slv(N, M, K, A, B))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,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])
import bisect
ans=0
for i in range(n+1):
    if A[i]<=k:
        j=bisect.bisect(B,k-A[i])
        temp=i+j-1
        ans=max(ans,temp)
print(ans)

Submission status: Accepted

Solution code:
#!python3

import bisect

LI = lambda: list(map(int, input().split()))

# input
N, M, K = LI()
A = LI()
B = LI()


def main():
    sa = [0] * (N + 1)
    for i in range(N):
        sa[i + 1] = sa[i] + A[i]
    sb = [0] * (M + 1)
    for i in range(M):
        sb[i + 1] = sb[i] + B[i]
    ans = 0
    for i in range(N + 1):
        a = sa[i]
        if a > K:
            break
        j = bisect.bisect_right(sb, K - a)
        ans = max(ans, i + j - 1)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N, M, K = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
b = list(map(int, input().split(" ")))

b_counter = [0]
for _b in b :
    b_counter.append(b_counter[-1]+_b)

res = 0
cur = 0
for i in range(N+1):    
    left = K-cur
    _i = 0
    _j = len(b_counter)-1
    while _i < _j :
        m = (_i+_j+1)//2
        if b_counter[m] <= left :
            _i = m
        else :
            _j = m-1
    if b_counter[_i] <= left :
        res = max(i+_i, res)

    if i == N : break 
    cur += a[i]

print(res)

Submission status: Accepted

Solution code:
from bisect import bisect_right
def main():
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    for i in range(n-1):
        a[i+1] += a[i]
    for i in range(m-1):
        b[i+1] += b[i]
    ans = bisect_right(b, k)
    for i in range(1, n+1):
        if k < a[i-1]:
            break
        x = k - a[i-1]
        tmp = i
        tmp += bisect_right(b, x)
        if ans < tmp:
            ans = tmp
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict, deque, Counter
import math

# import copy
from bisect import bisect_left, bisect_right
# import heapq

# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def solve():
    n,m,k = getList()
    anums = getList()
    bnums = getList()
    arui = []
    tmp = 0
    for num in anums:
        tmp += num
        arui.append(tmp)
    brui = []
    tmp = 0
    for num in bnums:
        tmp += num
        brui.append(tmp)
    ans = 0
    for i, ar in enumerate(arui):
        if ar <= k:
            nokori = k - ar
            byom = bisect_right(brui, nokori)
            tans = byom + i + 1
            if tans > ans:
                ans = tans

    tans = bisect_right(brui, k)
    if tans > ans:
        ans = tans
    print(ans)
def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    # main()
    solve()

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right
# bisect_left(a,x):a[i]>=xとなるような最小のi.
# 昇順ソートされたリストaに昇順を崩さずxを挿入できる位置s(0-index)を返す.
# a=[1,3,5,7,9,11,13,15,17,19]
#s = bisect_left(a,4)
# s=2
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]
a = [0] + a
for i in range(1, m):
    b[i] += b[i - 1]
ans = 0
for i in range(n + 1):
    if a[i] > k:
        break
    x = bisect_right(b, k - a[i])
    ans = max(x + i, ans)
print(ans)

Submission status: Accepted

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0] + list(reversed(b)) + a
for i in range(n + m):
    c[i + 1] += c[i]
r = m
ans = 0
for l in range(m + 1):
    while r <= n + m and c[r] - c[l] <= k:
        ans = max(ans, r - l)
        r += 1
print(ans)

Submission status: Accepted

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

now = sum(b)
j = len(b)
while j > 0 and now > k:
    j -= 1
    now -= b[j]
ans = j
for i, ai in enumerate(a, 1):
    now += ai
    while j > 0 and now > k:
        j -= 1
        now -= b[j]
    if now > k:
        break
    ans = max(ans, i + j)
print(ans)

Submission status: Accepted

Solution code:
from math import gcd

from math import factorial as f

from math import ceil,floor,sqrt
import math

import bisect
import re
import heapq


from copy import deepcopy
import itertools
from itertools import permutations

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


yes = "Yes"
no = "No"


def main():
    n,m,k = mi()
    a = li()
    b = li()
    arui = [0]
    brui = [0]
    tmp = 0
    ans = 0

    for i in range(n):
        tmp+=a[i]
        arui.append(tmp)
    tmp = 0
    for i in range(m):
        tmp+=b[i]
        brui.append(tmp)
    anstmp = 0
    for i in range(n+1):
        if arui[i]>k:
            break
        anstmp = i
        anstmp+=bisect.bisect_right(brui,k-arui[i])
        anstmp-=1
        ans = max(ans,anstmp)
    print(ans)



main()

Submission status: Accepted

Solution code:
import unittest


def main():
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    total_a = [0]*(n+1)
    total_b = [0] * (m + 1)
    for i in range(n):
        total_a[i+1] = total_a[i] + a[i]
    for i in range(m):
        total_b[i + 1] = total_b[i] + b[i]
    ai = 0
    bi = m
    max_v = 0
    while total_b[bi] > k:
        bi -= 1
    while ai <= n and total_a[ai] <= k:
        while bi > 0 and total_a[ai]+total_b[bi] > k:
            bi -= 1
        if total_a[ai]+total_b[bi] <= k:
            max_v = max(max_v, ai + bi)
        ai += 1
    print(max_v)


if __name__ == "__main__":
    main()


class TestAbc138_e(unittest.TestCase):
    def test_abc138_e(self):
        self.assertEqual(solve('contest', 'son'), 10)
        self.assertEqual(solve('contest', 'programming'), -1)
        self.assertEqual(solve('contest', 'sentence'), 33)
        self.assertEqual(solve('abc', 'abccccac'), 15)

Submission status: Accepted

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

def cumsum(a):
   r = [0]
   for v in a:
      r.append(r[-1] + v)
   return r

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

ans = 0
for a_num, v in enumerate(a):
   tmp = 0
   if k >= v:
      b_num = bisect.bisect_right(b, k - v) - 1
      tmp = a_num + b_num
   ans = max(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:
"""
NTC here
"""
 
 
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase

profile = 0
pypy = 1
 
 
def iin(): return int(input())


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


def main():
    n, m, k = lin()
    a = lin()
    b = lin()
    a1 = []
    sm = 0
    a2 = []
    for i in a:
        if sm+i<=k:
            a1.append(i)
            sm += i
        else:
            break
    ans = len(a1)
    for i in b:
        while a1 and sm+i>k:
            x = a1.pop()
            sm -= x
        if sm+i<=k:
            a2.append(i)
            sm += i
        else:
            break
        ans = max(ans, len(a1)+len(a2))
        # print(a1, a2)
    print(ans)
        










    




                

        

 
 
 
 
 
 
# region fastio
 
BUFSIZE = 8192
 
 
class FastIO(IOBase):
    newlines = 0
 
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
 
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
 
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
 
if pypy:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
    input = lambda: sys.stdin.readline().rstrip("\r\n")
 
# endregion
 
if __name__ == "__main__":
    if profile:
        import cProfile
        cProfile.run('main()')
    else:
        main()

Submission status: Accepted

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,M,K=MI()
    A=LI()
    B=LI()
    AS=[0]*(N+1)
    BS=[0]*(M+1)
    
    for i in range(N):
        AS[i+1]=AS[i]+A[i]
        
    for i in range(M):
        BS[i+1]=BS[i]+B[i]

    import bisect
    
    ans=0
    for i in range(N+1):
        at=AS[i]
        bt=K-at
        if bt<0:
            break
        j=bisect.bisect_right(BS,bt)-1
        temp=i+j
        ans=max(ans,temp)
        
    print(ans)
        

            

main()

Submission status: Accepted

Solution code:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
aa = [a[0]]
bb = [b[0]]
for i in range(1,n):
  aa.append(aa[-1]+a[i])
for i in range(1,m):
  bb.append(bb[-1]+b[i])
import bisect
#print(aa)
#print(bb)
ans = bisect.bisect_right(bb,k)
#print(ans)
for i in range(n):
  if aa[i] > k:
    #print(aa[i])
    break
  tmp = bisect.bisect_right(bb,k-aa[i])+i+1
  ans = max(ans,tmp)
  #print(tmp)
print(ans)

Submission status: Accepted

Solution code:
import bisect
N,M,K = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ac = [0]*(N+1)
bc = [0]*(M)
bc[0] = b[0]
for i,val in enumerate(a):
    ac[i+1] = ac[i] + val
for i,val in enumerate(b[1:]):
    bc[i+1] = bc[i] + val
res = 0
for i,val in enumerate(ac):
    if val > K:
        break
    rest = K-val
    idx = bisect.bisect_right(bc, rest)
    if idx+i > res:
        res = idx+i
print(res)

Submission status: Accepted

Solution code:
from itertools import accumulate
N, M, T = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

Asum = list(accumulate(A, initial=0))
Bsum = list(accumulate(B, initial=0))

ans = 0
j = 0
for i in reversed(range(N + 1)):
    x = Asum[i]
    if x > T:
        continue
    while j < M and Bsum[j + 1] + x <= T:
        j += 1
    ans = max(ans, i + j)

print(ans)

Submission status: Accepted

Solution code:
from itertools import accumulate
import bisect

n,m,K = map(int, input().split())
a = [0] + list(accumulate(list(map(int, input().split()))))
b = list(accumulate(list(map(int, input().split()))))
ans = 0
for k,v in enumerate(a):
    if v > K:
        break
    tmp = k + bisect.bisect_right(b,K-v)
    if tmp > ans:
        ans = tmp
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_right
from itertools import accumulate
N, M, K = map(int, input().split())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))

accA = list(accumulate(As)) + [0]
accB = list(accumulate(Bs))

ans = 0
for numA in range(N+1):
    t = accA[numA-1]
    if t > K:
        break
    numB = bisect_right(accB, K-t)
    tmp = numA + numB
    ans = ans if ans > tmp else tmp
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    N, M,K = map(int, input().split())
    A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    B = tuple(map(int, input().split()))
    A= list(accumulate(A))
    B= list(accumulate(B))
    ans=0
    ans=bisect_right(B,K)
    for i in range(N):
        a=A[i]
        if a>K:
            break
        ans=max(ans,i+1+bisect_right(B,K-a))
    print(ans)




if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right

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

res = 0

cA = [0]
for i in range(N):
    cA.append(cA[-1] + A[i])

cB = [0]
for i in range(M):
    cB.append(cB[-1] + B[i])

for i in range(N + 1):
    rem = K - cA[i]
    if rem < 0:
        continue
    j = bisect_right(cB, rem)
    res = max(res, i + j - 1)

print(res)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,m,k = LI()
    a = LI()
    b = LI()
    a = [0]+list(accumulate(a))
    b = [0]+list(accumulate(b))
    ans = 0
    for i in range(len(a)):
        sa = a[i]
        res = k-sa
        if res < 0:
            continue
        j = bisect.bisect_right(b,res)
        s = i+j-1
        if ans < s:
            ans = s
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Accepted

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

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

A.append(float("inf"))
B.append(float("inf"))
bs = [0]
for i in B:
    bs.append(bs[-1]+i)

ans = 0
now = 0

for i in range(N+1):

    ind = bisect.bisect_right(bs,K-now)-1

    ans = max(ans , i + ind)
    
    now += A[i]
    if now > K:
        break

print (ans)

Submission status: Accepted

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
for i in range(n-1):a[i+1]+=a[i]
for i in range(m-1):b[i+1]+=b[i]
from bisect import bisect_left,bisect_right
ans=bisect_right(b,k)
for i in range(n):
  if a[i]>k:break
  ans=max(ans,i+1+bisect_right(b,k-a[i]))
print(ans)

Submission status: Accepted

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

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

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

C = [0]
c = 0
for i in range(N):
    c+=A[i]
    C.append(c)

D = [0]
d = 0
for i in range(M):
    d+=B[i]
    D.append(d)

ans = 0

def bisect(m):
    if m>=D[M]:
        return M
    if m==0:
        return 0
    r = M
    l = 0
    while r-l>1:
        if m>=D[(r+l)//2]:
            l = (r+l)//2
        else:
            r = (r+l)//2
    return l

for i in range(N+1):
    if K<C[i]:
        break
    ans = max(i+bisect(K-C[i]),ans)
print(ans)

Submission status: Accepted

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

SA = 0
SB = sum(B)
Bn = len(B)
ans = 0
for An in range(len(A)+1):
  if An>0:
    SA += A[An-1]
  if SA>K:
    break
  while SA+SB>K:
    Bn -= 1
    SB -= B[Bn]
  ans = max(ans, An+Bn)
print(ans)

Submission status: Accepted

Solution code:
import sys
from bisect import bisect_right

import numpy as np

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N, M, K = map(int, input().split())
    A = [0] + list(map(int, input().split()))
    B = [0] + list(map(int, input().split()))
    a = np.cumsum(A)
    b = np.cumsum(B)

    ans = 0
    for i in range(N + 1):
        time = a[i]
        if time > K:
            continue
        idx = bisect_right(b, K - time)
        tmp = i + idx - 1
        if tmp > ans:
            ans = tmp

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from bisect import bisect_left,bisect_right
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
sa=[0]*(N+1)
sb=[0]*(M+1)
for i in range(N):
    sa[i+1]=sa[i]+A[i]
for i in range(M):
    sb[i+1]=sb[i]+B[i]
ans=0
for i in range(N+1):
    if sa[i]<=K:
        res=bisect_right(sb,K-sa[i])
        tmp=i+res-1
        ans=max(ans,tmp)
print(ans)

Submission status: Accepted

Solution code:
mod = 1000000007
eps = 10**-9


def main():
    import sys
    from bisect import bisect_left
    input = sys.stdin.readline

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

    cs_A = [0] * (N+1)
    cs_B = [0] * (M+1)
    for i in range(N):
        cs_A[i+1] = cs_A[i] + A[i]
    for i in range(M):
        cs_B[i+1] = cs_B[i] + B[i]

    ans = 0
    for i in range(N+1):
        if cs_A[i] > K:
            break
        j = bisect_left(cs_B, K - cs_A[i] + 1) - 1
        if j == M+1:
            j = M
        ans = max(i+j, ans)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from bisect import bisect
from itertools import accumulate

n, m, k, *ab = map(int, sys.stdin.buffer.read().split())
aaa = [0] + ab[:n]
bbb = [0] + ab[n:]
acc = list(accumulate(aaa))
bcc = list(accumulate(bbb))

ans = 0
for i in range(n + 1):
    r = k - acc[i]
    if r < 0:
        break
    j = bisect(bcc, r) - 1
    ans = max(ans, i + j)
print(ans)

Submission status: Accepted

Solution code:
import bisect
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=bisect.bisect_right(B,K)
for i in range(0,N):
    if K>=A[i]:
        temp=i+1
        id=bisect.bisect_right(B,K-A[i])
        temp+=id
        ans=max(ans,temp)


print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a_cs = [0] * (n + 1)
b_cs = [0] * (m + 1)

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

ans = 0
for i in range(n + 1):
    if a_cs[i] <= k:
        cand = i
        cand += bisect_right(b_cs, k - a_cs[i]) - 1
        ans = max(ans, cand)

print(ans)

Submission status: Runtime Error

Solution code:
n,m,k = map(int,input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A,B = [0],[0]
 
for i in range(n):
  A.append(a[i] + A[i])
for i in range(m):
  B.append(b[i] + B[i])
 
num,x = 0,m-1
A.pop(0)
B.pop(0)
 
for i in range(len(A)):
  if A[i] > k:
    break
  while A[i] + B[x] > k:
    x -= 1
  num = max(num, i + x + 2)
  
print(num)

Submission status: Runtime Error

Solution code:
n,m,k = map(int,input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A,B = [0],[0]
 
for i in range(n):
  A.append(a[i] + A[i])
for i in range(m):
  B.append(b[i] + B[i])
 
num,x = 0,m-1
A.pop(0)
B.pop(0)
 
for i in range(len(A)-1):
  if A[i] > k:
    break
  while A[i] + B[x] > k:
    x -= 1
  num = max(num, i + x + 2)
  
print(num)

Submission status: Runtime Error

Solution code:
n,m,k = map(int,input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A,B = [0],[0]
 
for i in range(n):
  A.append(a[i] + A[i])
for i in range(m):
  B.append(b[i] + B[i])
 
num,x = 0,m-1
A.pop(0)
B.pop(0)
 
for i in range(len(a)+1):
  if A[i] > k:
    break
  while A[i] + B[x] > k:
    x -= 1
  num = max(num, i + x + 2)
  
print(num)
n,m,k = map(int,input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A,B = [0],[0]
 
for i in range(n):
  A.append(a[i] + A[i])
for i in range(m):
  B.append(b[i] + B[i])
 
num,x = 0,m-1
A.pop(0)
B.pop(0)
 
for i in range(len(A)-1):
  if A[i] > k:
    break
  while A[i] + B[x] > k:
    x -= 1
  num = max(num, i + x + 2)
  
print(num)

Submission status: Runtime Error

Solution code:
n,m,k = map(int,input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A,B = [0],[0]
 
for i in range(n):
  A.append(a[i] + A[i])
for i in range(m):
  B.append(b[i] + B[i])
 
num,x = 0,m-1
A.pop(0)
B.pop(0)
 
for i in range(len(a)+1):
  if A[i] > k:
    break
  while A[i] + B[x] > k:
    x -= 1
  num = max(num, i + x + 2)
  
print(num)
n,m,k = map(int,input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A,B = [0],[0]
 
for i in range(n):
  A.append(a[i] + A[i])
for i in range(m):
  B.append(b[i] + B[i])
 
num,x = 0,m-1
A.pop(0)
B.pop(0)
 
for i in range(len(A)):
  if A[i] > k:
    break
  while A[i] + B[x] > k:
    x -= 1
  num = max(num, i + x + 2)
  
print(num)

Submission status: Runtime Error

Solution code:
n,m,k = map(int,input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A,B = [0],[0]
 
for i in range(n):
  A.append(a[i] + A[i])
for i in range(m):
  B.append(b[i] + B[i])
 
num,x = 0,m-1
A.pop(0)
B.pop(0)
 
for i in range(len(a)+1):
  if A[i] > k:
    break
  while A[i] + B[x] > k:
    x -= 1
  num = max(num, i + x + 2)
  
print(num)