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

A = li()
B = li()

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

cnt = ans = 0

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

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

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

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

A = li()
B = li()

A = [0] + list(accumulate(A))
B = list(accumulate(B))
ans = 0

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

print(ans)

Submission status: Accepted

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

n,m,k = mi()
a = li()
b = li()

asum = sum(a)
acur = n-1
bsum = 0
bcur = -1

# acumsum = []
# bcumsum = []
# atmp = 0
# btmp = 0
# for i in range(n):
#     atmp += a[i]
#     acumsum.append(atmp)
# for i in range(m):
#     btmp += b[i]
#     bcumsum.append(btmp)

if asum > k:
    while asum > k:
        asum -= a[acur]
        acur -= 1
    while 1:
        if asum + bsum + b[bcur+1] <= k:
            bsum += b[bcur+1]
            bcur += 1
        else:
            break
        if bcur == m-1:
            break
else:
    while 1:
        if asum + bsum + b[bcur+1] <= k:
            bsum += b[bcur+1]
            bcur += 1
        else:
            break
        if bcur == m-1:
            break

read_max = acur + 1 + bcur + 1

# print(read_max)
# print(acur+1,bcur+1)

# print(acumsum)
# print(bcumsum)



for i in range(n):
    acur -= 1
    if acur == -2:
        break
    
    asum -= a[acur+1]
    if bcur == m-1:
        break

    while 1:
        if asum + bsum + b[bcur+1] <= k:
            bsum += b[bcur+1]
            bcur += 1
        else:
            break
        if bcur == m-1:
            break

    # print('cur',acur+1,bcur+1,asum+bsum)

    read_max = max(read_max, acur + 1 + bcur + 1)

    if bcur == m-1:
        break
print(read_max)

Submission status: Accepted

Solution code:
import numpy as np
from functools import reduce

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


def get_cum(arr):
    cum_arr = [0]
    for e in arr:
        tot = cum_arr[-1] + e
        if tot > K:
            return cum_arr
        cum_arr.append(tot)
    return cum_arr


cumA = get_cum(As)
cumB = get_cum(Bs)

max_count = 0
a_thresh = len(cumA) - 1
a_count = a_thresh
b_count = 0
b_thresh = len(cumB) - 1
while a_count >= 0 and b_count <= b_thresh:
    while b_count <= b_thresh and cumA[a_count] + cumB[b_count] <= K:
        b_count += 1
    b_count = max(0, b_count - 1)
    if cumA[a_count] + cumB[b_count] <= K:
        max_count = max(max_count, a_count + b_count)
    a_count -= 1

print(max_count)

Submission status: Accepted

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

tmp=0
ca=[0]
for ai in a:
  tmp+=ai
  ca.append(tmp)
tmp=0
cb=[0]
for bi in b:
  tmp+=bi
  cb.append(tmp)
import bisect
s=bisect.bisect_right(ca,k)-1
ans=ca[s]
now_a=s
z=k-ca[now_a]
now_b=bisect.bisect_right(cb,z)-1
t=ca[now_a]+cb[now_b]
#print(now_a,now_b)
ans=now_a+now_b
for i in range(s):
  now_a-=1
  t-=a[now_a]
  while now_b<m and t+b[now_b]<=k:
    t+=b[now_b]
    now_b+=1
  ans=max(ans,now_a+now_b)
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=[]
ka=0
sb=[]
kb=0
for i in range(n):
  if ka+a[i]<=k:
    ka+=a[i]
    sa.append(a[i])
  else:
    break
for i in range(m):
  if kb+b[i]<=k:
    kb+=b[i]
    sb.append(b[i])
  else:
    break
ans=max(len(sa),len(sb))
tb=[]
for i in range(len(sa)):
  if sa[i]>k:
    break
  while kb+sa[i]>k:
    kb-=sb[-1]
    sb.pop(-1)
  tb.append(sa[i])
  kb+=sa[i]
  if ans<(len(sb)+len(tb)):
    ans=(len(sb)+len(tb))
print(ans)

Submission status: Accepted

Solution code:
n, m, k = [int(v) for v in input().split()]
alist = [int(v) for v in input().split()]
blist = [int(v) for v in input().split()]

consumed = 0
max_count = 0

i = 0
while i < len(alist) and consumed + alist[i] <= k:
    consumed += alist[i]
    i += 1

j = 0
while j < len(blist) and consumed + blist[j] <= k:
    consumed += blist[j]
    j += 1

count = i + j
max_count = count

i -= 1

while i >= 0:
    consumed -= alist[i]
    count -= 1
    while j < len(blist) and consumed + blist[j] <= k:
        consumed += blist[j]
        j += 1
        count += 1
        if count > max_count:
            max_count = count
    i -= 1

print(max_count)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    N, M, K = Scanner.map_int()
    A = Scanner.map_int()
    B = Scanner.map_int()
    time = 0
    ans = 0
    for a in A:
        if time + a > K:
            break
        time += a
        ans += 1
    x = ans
    j = 0
    while time <= K and j < M:
        if time + B[j] > K:
            break
        time += B[j]
        j += 1
        ans += 1
    tmp = ans
    for i in reversed(range(x)):
        time -= A[i]
        tmp -= 1
        while time <= K and j < M:
            if time + B[j] > K:
                break
            time += B[j]
            j += 1
            tmp += 1
        ans = max(ans, tmp)
    print(ans)


def main():
    # sys.setrecursionlimit(1000000)
    # sys.stdin = open("sample.txt")
    # T = Scanner.int()
    # for _ in range(T):
    #     solve()
    # print('YNeos'[not solve()::2])
    solve()


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
# INF = float("inf")
import sys

N,M,K = map(int,sys.stdin.readline().split())
a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
b = tuple(map(int,sys.stdin.readline().split())) # single line with multi param

cum_a = [0]*(N+1)
for i in range(N):
    cum_a[i+1] = cum_a[i]+a[i]

cum_b = [0]*(M+1)
for i in range(M):
    cum_b[i+1] = cum_b[i]+b[i]

ok = 0
ng = N+M+1

def isOK(mid):
    for i in range(N+1):
        if 0 <= mid-i and mid-i <=M and cum_a[i]+cum_b[mid-i]<=K:
            return True
    return False

while ng-ok > 1:
    mid = (ok+ng)//2
    if isOK(mid):
        ok = mid
    else:
        ng = mid
print(ok)

Submission status: Accepted

Solution code:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
As=[0]*(N+1)+[float('inf')]
Bs=[0]*(M+1)+[float('inf')]
Amax=N
Bmax=M
for i in range(1,N+1):
    As[i]=As[i-1]+A[i-1]
    if As[i]>K:
        Amax=i
        break
for i in range(1,M+1):
    Bs[i]=Bs[i-1]+B[i-1]
    if Bs[i]>K:
        Bmax=i
        break

b=0
ans=0
for i in range(Amax,-1,-1):
    while As[i]+Bs[b]<=K:
        b+=1
    ans=max(ans,i+b-1)
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()))
sa = [0]
for i in range(n):
    sa.append(sa[-1] + a[i])
sb = [0]
for i in range(m):
    sb.append(sb[-1] + b[i])
ans = 0
for i, s in enumerate(sa):
    if s > k:
        break
    ans = max(ans, i + max(0, bisect.bisect_left(sb, k - s + 1) - 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()))
a_sum = [0] * (n + 1)
b_sum = [0] * (m + 1)
for i in range(n):
    a_sum[i + 1] = a_sum[i] + a[i]
for i in range(m):
    b_sum[i + 1] = b_sum[i] + b[i]
ans = -1
for i in range(n + 1):
    if a_sum[i] <= k:
        ans = i
    else:
        break
tmp = ans
for i in range(1, m + 1):
    if b_sum[i] > k:
        break
    for j in range(tmp, -1, -1):
        if b_sum[i] + a_sum[j] <= k:
            tmp = j
            ans = max(ans, i + j)
            break
print(ans)

Submission status: Accepted

Solution code:
def solve():
    tmp = 0
    a_sum = [0]
    for a in A:
        tmp += a
        a_sum.append(tmp)

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

    b_idx = 0
    a_idx = N
    ret = 0
    while 0 <= a_idx:
        if K < a_sum[a_idx]:
            a_idx -= 1
            continue
        while b_idx < M and a_sum[a_idx] + b_sum[b_idx + 1] <= K:
            b_idx += 1
        ret = max(ret, a_idx + b_idx)
        a_idx -= 1
    print(ret)

if __name__ == "__main__":
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    solve()

Submission status: Accepted

Solution code:

n, m, k = map(int, input().split())
from bisect import bisect_right

a = list(map(int, input().split()))
b = list(map(int, input().split()))
total_a = [0] * n
total_b = [0] * m

def set_data(data, a, x):
    data[0] = a[0]
    for i in range(1, x):
        data[i] = data[i - 1] + a[i]

set_data(total_a, a, n)
set_data(total_b, b, m)

def cnt(a, b, n, m):
    ans = 0
    for i in range(n - 1, -1, -1):
        if a[i] <= k:
            index = bisect_right(b, k - a[i], 0, m)
            ans = max(ans, i + index + 1)
    return ans

print(max(cnt(total_a, total_b, n, m), cnt(total_b, total_a, m, n)))

Submission status: Accepted

Solution code:
x0=input().split()
a0=int(x0[0])
b0=int(x0[1])
min=int(x0[2])

a1=input().split()
al=[int(x) for x in a1]
b1=input().split()
bl=[int(x) for x in b1]

ar=[0]
ar0=0
for x in al:
  ar0+=x
  ar.append(ar0)
  if ar0>min:
    break
an=len(ar)
if an-1==len(al):
  ar.append(1000000001)
  an+=1

br=[0]
br0=0
for x in bl:
  br0+=x
  br.append(br0)
  if br0>min:
    break
bn=len(br)
if bn-1==len(bl):
  br.append(1000000001)
  bn+=1

#print(str(br))
ans=0
if an==2:
  ans=bn-2
elif bn==2:
  ans=an-2
else:
  bnow=0
  for i in range(an-2,-1,-1):
    #print("i="+str(i))
    if i+bn-2<=ans:
      break
    bcan=min-ar[i]
    for j in range(bnow,bn):
      if bcan>=br[j]:
        #print("j="+str(j))
        bnow+=1
      else:
        #print("j^="+str(j))
        ans1=i+j-1
        if ans1>ans:
          ans=ans1
        break
    if bnow==bn-2:
      break
      
print(ans)

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
i = 0
while i < len(a) and x >= a[i]:
    x -= a[i]
    i += 1

f = i
j = 0
for p in b:
    j += 1
    x -= p
    
    while x < 0 and i > 0:
        i -= 1
        x += a[i]
    
    if x >= 0: f = max(f, j + i)

print(f)

Submission status: Accepted

Solution code:
n,m,k=map(int, input().split())
*a,=map(int, input().split())
*b,=map(int, input().split())
now=0
cnt=0
from itertools import accumulate  
a=list(accumulate(a))
a=[0]+a
b=list(accumulate(b))

from bisect import bisect_right
tmp=0
for i in range(n+1):
    ta=k-a[i]
    nb=bisect_right(b,ta)
    if ta>=0:
        tmp=max(tmp,nb+i)
        #print(nb,i)
print(tmp)

Submission status: Accepted

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

#n, m, k = 3, 4, 730
#a = [60, 90, 120]
#b = [80, 150, 80, 150]

a = [0] + a
for i in range(n):
    a[i + 1] = a[i] + a[i + 1]

b = [0] + b
for i in range(m):
    b[i + 1] = b[i] + b[i + 1]
    
ans = 0
for i in range(n + 1):
    for j in range(max(0, ans - i + 1), m + 1):
        if a[i] + b[j] <= k:
            ans = i + j
        else:
            break

print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000000)
import math
import bisect
from collections import deque
def input():
    return sys.stdin.readline()[:-1]

n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
sa = [0]
sb = [0]
for i in range(n):
    sa.append(sa[-1]+a[i])
for i in range(m):
    sb.append(sb[-1]+b[i])
anst = 0
ans = 0
#print(sa)
#print(sb)
for i in range(n+1):
    tmp = k
    tmp-=sa[i]
    if tmp<0:
        continue
    iti = bisect.bisect_right(sb,tmp)
    #print(tmp,i,iti)
    anst = i+iti-1
    ans = max(ans,anst)

print(ans)

Submission status: Accepted

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


def solve(N: int, M: int, K: int, A: "List[int]", B: "List[int]"):
    SA = [0]
    SB = [0]
    for i in range(N):
        SA.append(SA[-1]+A[i])
    for i in range(M):
        SB.append(SB[-1]+B[i])
    acount = 0
    acost = 0
    for i in range(1,len(SA)):
        if SA[i] <= K:
            acount += 1
            acost = SA[i]
        else:
            break
    bcost = 0
    bcount = 0
    for i in range(1,len(SB)):
        if SB[i] + acost <= K:
            bcount += 1
            bcost = SB[i]
        else:
            break
    # print(f"acount{acount},bcount{bcount} acost{acost} bcost{bcost}")
    if acount == N and bcount == M:
        print(acount+bcount)
    else:
        mb = 0
        bi = 0
        for aindex in range(acount,-1,-1):
            acost = SA[aindex]
            while bi < M and acost + SB[bi+1] <=K:
                bi += 1
            # print(f"aindex{aindex} - acost{acost} bi{bi} bcost{SB[bi]}")
            mb = max(mb,aindex+bi)
        print(mb)


    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int(next(tokens)) for _ in range(M)]  # type: "List[int]"
    solve(N, M, K, A, B)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# 解法 全探索をする，上から読んでる冊数をi,jとしてKを超えない範囲で最大のものを週つ力すれば良い
# 全探索だったらだめだったN^2になるから
# まずAを最大限選ぶ，次にその時選べる最大のBを選ぶ
N,M,K = map(int,input().split())

A = list(map(int,input().split()))
B = list(map(int,input().split()))
# 累積和
suma = 0
sumb = 0

As = [0]*N
for i,a in enumerate(A):
    suma += A[i]
    As[i] = suma

Bs = [0]*M
for i,b in enumerate(B):
    sumb += B[i]
    Bs[i] = sumb
sum_time=0
max_count = 0
count = 0
# i,jは実際に読んでいる数とする
import bisect
for i in range(N+1):
    count = 0
    if i ==0:
        sum_time=0
    else:
        sum_time=As[i-1]
        count += i
    if sum_time>K:
        continue
    ind = bisect.bisect_right(Bs,K-sum_time)
    count += ind
    max_count = max(max_count,count)

print(max_count)

Submission status: Accepted

Solution code:
def sumup(l):
  k=[0]
  y=0
  for x in l:
    y+=x
    k.append(y)
  return k


ans=[]
n,m,k=map(int,input().split())
al=list(map(int,input().split()))
bl=list(map(int,input().split()))

al=sumup(al)
bl=sumup(bl)

for i in range(n+1):
  x=al[i]

  while True:
    if not bl:
      break
    
    else:
      b=bl[-1]
      if x+b>k : 
        bl.pop()

      else: 
        ans.append(i+len(bl)-1)
        break
print(max(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()))
A=[0]+A
B=[0]+B

from itertools import accumulate

AA=list(accumulate(A))
BB=list(accumulate(B))
count=0
a,b=0,0

import bisect
for i in range(N+1):
    a=i
    b=bisect.bisect_right(BB,K-AA[i])-1
    if b==-1:
        continue
    count=max(count,a+b)
print(count)

Submission status: Accepted

Solution code:
from itertools import accumulate
from bisect import bisect_left

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

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

Ac=[0]+list(accumulate(A))
Bc=[0]+list(accumulate(B))
ans=0
for i,ac in enumerate(Ac):
    j=bisect_left(Bc,K-ac)

    for k in range(j-1,min(j+2,M+1)):
        if ac+Bc[k]<=K:
            ans=max(ans,i+k)

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
"""
import bisect

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

    A_sum_list = [0] + A_lsit[:]
    for i in range(1, N+1):
        A_sum_list[i] = A_sum_list[i-1] + A_lsit[i-1]
    B_sum_list = [0] + B_lsit[:]
    for i in range(1, M+1):
        B_sum_list[i] = B_sum_list[i-1] + B_lsit[i-1]
    #print(A_sum_list)
    #print(B_sum_list)

    max_book_number = 0
    for i in range(N+1):
        if A_sum_list[i] <= K:
            book_number_A = i
            book_number_B = bisect.bisect_right(B_sum_list, K-A_sum_list[i]) - 1
            max_book_number = max(
                max_book_number,
                book_number_A + book_number_B
            )
            #print(book_number_A, book_number_B, book_number_A + book_number_B)
    print(max_book_number)

if __name__ == "__main__":
    main()

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()))
ax = [0]*(n+1)
bx = [0]*(m+1)
for i in range(1,n+1):
    ax[i]=ax[i-1]+a[i-1]
for i in range(1,m+1):
    bx[i]=bx[i-1]+b[i-1]

c = bisect.bisect_right(ax,k)
ma = 0
for i in range(c):
    d = bisect.bisect_right(bx,k-ax[i])
    ma = max(ma,i+d-1)
print(ma)

Submission status: Accepted

Solution code:
from itertools import accumulate
import bisect
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
aa=[0]+list(accumulate(a))
b=[0]+list(map(int,input().split()))
bb=list(accumulate(b))
ans=0
for i in range(n+1):
    if aa[i]>k:
        break
    tmp=k-aa[i]
    t=bisect.bisect(bb,tmp)
    if i-1+t>ans:
        ans=i+t-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()))

aa=[a[0]]
for i in range(n-1):
    aa.append(aa[i]+a[i+1])
aa.insert(0,0)
bb=[b[0]]
for i in range(m-1):
    bb.append(bb[i]+b[i+1])
    
import bisect
l=[]
for i in range(n+1):
    p=k-aa[i]
    if p>=0:
        l.append(i+bisect.bisect_right(bb,p))
    else:
        break
print(max(l))

Submission status: Accepted

Solution code:
# coding: utf-8

from bisect import bisect_left


def leq_search(xs, x, s, t):
    # x以下で最大のindex
    if t-s <= 5:
        res = 0
        for i in range(s, t):
            if xs[i] <= x:
                res = i
        return res

    i = (s+t)//2
    if xs[i] <= x:
        return leq_search(xs, x, i, t)
    else:
        return leq_search(xs, x, s, i)


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

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

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

    n_read = 0
    for i in range(N+1):
        # print(i)
        if S[i] > K:
            break
        n = leq_search(T, K-S[i], 0, M+1)
        # print(n, T, K-S[i])
        if n_read < n + i:
            n_read = n + i
    
    return n_read


print(main())

Submission status: Accepted

Solution code:
import bisect
def main():

    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    prefixA = [0]
    for j in range(N):
        prefixA.append(prefixA[-1] + A[j])
    prefixB = [0]
    for j in range(M):
        prefixB.append(prefixB[-1] + B[j])

    ans = 0
    for i in range(N+1):
        v = prefixA[i]
        j = bisect.bisect_left(prefixB, K-v)
        if j< len(prefixB) and prefixB[j] + v <= K:
            ans = max(ans, i + j)
        if j-1 >=0 and prefixB[j-1] + v <= K:
            ans = max(ans, i + j-1)
    return ans


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

Submission status: Accepted

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()))
SA = [0]
for i in range(N):
  temp = SA[-1] + A[i]
  SA.append(temp)

SB = [0]
for j in range(M):
  temp = SB[-1] + B[j]
  SB.append(temp)
ans = 0
for i in range(N+1):
  an = i
  if SA[i] > K:
    break
  else:
    nokori = K -SA[i]
    if nokori >= SB[-1]:
      bn = M
    else:
      ok = 0
      ng = M
      while abs(ok-ng) > 1:
        mid = (ok+ng)//2
        if nokori >= SB[mid]:
          ok = mid
        else:
          ng = mid
      bn = ok
  #print(an,bn)
  ans = max(ans,an+bn)
print(ans)

Submission status: Accepted

Solution code:
import math
import time
from collections import defaultdict, deque
from sys import stdin, stdout
from bisect import bisect_left, bisect_right,bisect
n,m,k=map(int,stdin.readline().split())
a=list(map(int,stdin.readline().split()))
b=list(map(int,stdin.readline().split()))
prea=[]
ans=0
for i in a:
    ans+=i 
    prea.append(ans)
final=bisect(prea,k)
temp=0
for i in range(m):
    temp+=b[i]
    if(temp>k):
        break
    temp2=bisect(prea,k-temp)
    final=max(final,temp2+i+1)
print(final)

Submission status: Accepted

Solution code:
N,M,K = map(int,input().split())
import bisect
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
sa = [0]*(N+1)
lim = N
for i in range(N):
    sa[i+1] = sa[i] + A[i]
    if sa[i+1] > K:
        lim = i
        break

sb = [0]*(M+1)
for i in range(M):
    sb[i+1] = sb[i] + B[i]
sb = sb[1:]

# print(sa)
# print(sb)

for reada in range(lim+1): # Nまで読む
    temp = sa[reada]
    # print(K-temp)
    cand = bisect.bisect_right(sb,K-temp)
    # print(reada, cand + reada,cand)
    ans = max(ans,cand + reada)
print(ans)

Submission status: Accepted

Solution code:
N,M,K = map(int,input().split())
lA = list(map(int, input().split()))
lB = list(map(int, input().split()))
aA = []
aB = []
m = 0
k = 0
for A in lA:
    nx = k + A
    if nx > K:
        break
    aA.append(A)
    k = nx
    m += 1
for B in lB:
    nx = k + B
    if nx > K:
        break
    aB.append(B)
    k = nx
    m += 1
aA.reverse()
aB.reverse()
M = m
i = len(aB)
for A in aA:
    k = k - A
    m -= 1
    while i < len(lB):
        nx = k + lB[i]
        if nx > K:
            break
        k = nx
        m += 1
        if m > M:
            M = m
        i += 1
print(M)

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

from itertools import accumulate
import bisect

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

ans = 0
for ac in range(n+1):
    if A[ac] > k:
        break
    bc = bisect.bisect_right(B, k-A[ac])
    ans = max(ans, ac+bc)

print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_right as br


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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from itertools import accumulate
import bisect
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
i = 0
j = 0
total = 0

ac = list(accumulate(a))
bc = list(accumulate(b))

ans = 0
for i in range(bisect.bisect(ac, k)):
    bi = bisect.bisect(bc, k - ac[i])
    ans = max(ans, i+1+bi)
for i in range(bisect.bisect(bc, k)):
    bi = bisect.bisect(ac, k - bc[i])
    ans = max(ans, i+1+bi)
ans = max(ans, bisect.bisect(ac, k))
ans = max(ans, bisect.bisect(bc, k))
print(ans)

Submission status: Accepted

Solution code:
from itertools import accumulate
from bisect import bisect_left

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
acc_A = [0] + list(accumulate(A))
acc_B = [0] + list(accumulate(B))
res = 0
for i, a in enumerate(acc_A):
    if a > K:
        break
    idx = bisect_left(acc_B, K - a)
    idx = min(idx, M)
    if acc_B[idx] > K - a:
        idx -= 1
    res = max(res, i + idx)
print(res)

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()))
ca = A[:]
cb = B[:]

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

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

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

Submission status: Accepted

Solution code:
INF = 10**10
N,M,K = map(int,input().split())
A = [0]+list(map(int,input().split()))+[INF]
B = [0]+list(map(int,input().split()))+[INF]
tmp = 0
i = 0
j = 0
while tmp+A[i+1]<=K:
    tmp += A[i+1]
    i += 1
while tmp+B[j+1]<=K:
    tmp += B[j+1]
    j += 1
ans = i+j
while i>0:
    tmp -= A[i]
    i -= 1
    while tmp+B[j+1]<=K:
        tmp += B[j+1]
        j += 1
    ans = max(ans,i+j)
print(ans)